import type { Filter, UpdateFilter } from "mongodb"; import { CreateIndexesOptions, Db, IndexSpecification } from "mongodb"; declare type MaybePromise = Promise | T; export interface JWTUser { id: string; sub: string; } export interface PolicyExecutionContext { user?: User; } export interface ReadPolicyExecutionContext extends PolicyExecutionContext { } export interface CreatePolicyExecutionContext extends PolicyExecutionContext { doc: TDoc; } export interface UpdatePolicyExecutionContext extends PolicyExecutionContext { } export interface UpdateOperationsPolicyExecutionContext extends PolicyExecutionContext { doc: TDoc; updateFilter: UpdateFilter; } export interface DeletePolicyExecutionContext extends PolicyExecutionContext { } export declare type FilterPolicyResult = MaybePromise | true | false>; export declare type UpdateOperationsACL = Partial>; export declare type OperationACL = string[] | { exclude?: string[]; include?: string[]; } | undefined; /** * Determines the set of documents that the user is allowed to create. * * @description * return true to allow reading any document, * false to forbid reading any document, * Filter to allow reading documents that match the filter */ export declare type ReadAccessPolicy = (ctx: ReadPolicyExecutionContext) => FilterPolicyResult; /** * Determines whether the user is allowed to create the document. * * @description * return true to allow creating the document, * false to forbid creating the document, */ export declare type CreateAccessPolicy = (ctx: CreatePolicyExecutionContext) => MaybePromise; /** * Determines the set of documents that the user is allowed to update. * * @description * return true to allow updating any document, * false to forbid updating any document, * Filter to allow updating documents that match the filter. */ export declare type UpdateAccessPolicy = (ctx: UpdatePolicyExecutionContext) => FilterPolicyResult; /** * Determines the set of update operations that the user is allowed to perform on the document. * * @description * return true to allow the updates on the document, * false to forbid the updates on the document. */ export declare type UpdateOperationsPolicy = (ctx: UpdateOperationsPolicyExecutionContext) => MaybePromise; /** * Determines the set of documents that the user is allowed to delete. * * @description * return true to allow deleting any document, * false to forbid deleting any document, * Filter to allow deleting documents that match the filter. */ export declare type DeleteAccessPolicy = (ctx: DeletePolicyExecutionContext) => FilterPolicyResult; interface PolicyModule { requireAuthentication: boolean; } export declare type UpdateFilterKeys = '$currentDate' | '$inc' | '$min' | '$max' | '$mul' | '$rename' | '$set' | '$setOnInsert' | '$unset' | '$addToSet' | '$pop' | '$pull' | '$push' | '$pullAll' | '$bit'; export interface UpdatePolicyModule extends PolicyModule { default?: UpdateAccessPolicy; allowOperations?: UpdateFilterKeys[]; getFilterPolicy?: UpdateOperationsPolicy; } export interface EventContext { eventName: string; user: JWTUser; db: Db; } export interface CreatedEventContext extends EventContext { doc: TDoc; } export interface UpdatedEventContext extends EventContext { oldDoc: TDoc; newDoc: TDoc; } export interface DeletedEventContext extends EventContext { doc: TDoc; } export declare type CreatedEventHandler = (ctx: CreatedEventContext) => MaybePromise; export declare type UpdatedEventHandler = (ctx: UpdatedEventContext) => MaybePromise; export declare type DeletedEventHandler = (ctx: DeletedEventContext) => MaybePromise; export declare type IndexConfig = { fields: IndexSpecification; options?: CreateIndexesOptions; }; export {};