import { AnyMongoAbility, MongoAbility } from './Ability'; import { ProduceGeneric } from './hkt'; import { AbilityOptionsOf, AnyAbility } from './PureAbility'; import { Generics, RawRuleOf } from './RuleIndex'; import { AbilityTuple, AnyClass, AnyObject, ExtractSubjectType as E, Normalize, SubjectType, TaggedInterface } from './types'; declare class RuleBuilder { _rule: RawRuleOf; constructor(rule: RawRuleOf); because(reason: string): this; } type AbilityFactory = AnyClass | ((rules?: any[], options?: any) => T); type InstanceOf = S extends AnyClass ? R : S extends (...args: any[]) => infer O ? O : S extends string ? Exclude['abilities']>[1], SubjectType> extends TaggedInterface ? Extract['abilities']>[1], TaggedInterface> : AnyObject : never; type ConditionsOf = ProduceGeneric['conditions'], I>; type ActionFrom = T extends any ? S extends Extract ? T[0] : never : never; type ActionOf = ActionFrom['abilities'], S>; type SubjectTypeOf = E['abilities']>[1]>; type SimpleCanParams = Parameters<(action: Generics['abilities'] | Generics['abilities'][]) => 0>; type BuilderCanParameters, T extends AnyAbility> = Generics['abilities'] extends AbilityTuple ? Parameters<(action: ActionOf | ActionOf[], subject: S | S[], conditions?: ConditionsOf) => 0> : SimpleCanParams; type BuilderCanParametersWithFields, F extends string, T extends AnyAbility> = Generics['abilities'] extends AbilityTuple ? Parameters<(action: ActionOf | ActionOf[], subject: S | S[], fields?: F | F[], conditions?: ConditionsOf) => 0> : SimpleCanParams; type Keys = string & keyof T; type AddRule = { , F extends string = Keys, S extends SubjectTypeOf = SubjectTypeOf>(...args: BuilderCanParametersWithFields, T>): RuleBuilder; , S extends SubjectTypeOf = SubjectTypeOf>(...args: BuilderCanParameters): RuleBuilder; }; export declare class AbilityBuilder { rules: RawRuleOf[]; private readonly _createAbility; can: AddRule; cannot: AddRule; build: (options?: AbilityOptionsOf) => T; constructor(AbilityType: AbilityFactory); private _addRule; } type DSL = (can: AbilityBuilder['can'], cannot: AbilityBuilder['cannot']) => R; export declare function defineAbility(define: DSL>, options?: AbilityOptionsOf): Promise; export declare function defineAbility(define: DSL, options?: AbilityOptionsOf): T; export {};