11import { createAuthorizationError } from './error'
2- import type { AuthorizationResponse , AuthorizerResponse , BouncerAbility } from './types'
2+ import type { AuthorizationResponse , BouncerAbility , BouncerArgs } from './types'
33
44/**
55 * Normalize the ability execution result to an authorization response.
@@ -15,23 +15,23 @@ export function normalizeAuthorizationResponse(result: boolean | AuthorizationRe
1515/**
1616 * Check if a user can perform an action.
1717 */
18- export async function allows < Ability extends BouncerAbility < any > , User > ( bouncerAbility : Ability , user : User , ... args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < boolean > {
18+ export async function allows < Ability extends BouncerAbility < any > , User extends Record < string , any > = Ability extends BouncerAbility < infer U > ? U : never > ( bouncerAbility : Ability , user : User | null , ...args : BouncerArgs < Ability > ) : Promise < boolean > {
1919 const response = await bouncerAbility . execute ( user , ...args )
2020 return normalizeAuthorizationResponse ( response ) . authorized
2121}
2222
2323/**
2424 * Check if a user cannot perform an action.
2525 */
26- export async function denies < Ability extends BouncerAbility < any > , User > ( bouncerAbility : Ability , user : User , ... args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < boolean > {
26+ export async function denies < Ability extends BouncerAbility < any > , User extends Record < string , any > = Ability extends BouncerAbility < infer U > ? U : never > ( bouncerAbility : Ability , user : User | null , ...args : BouncerArgs < Ability > ) : Promise < boolean > {
2727 const response = await bouncerAbility . execute ( user , ...args )
2828 return ! normalizeAuthorizationResponse ( response ) . authorized
2929}
3030
3131/**
3232 * Check if a user can perform an action and throws an error if not.
3333 */
34- export async function authorize < Ability extends BouncerAbility < any > , User > ( bouncerAbility : Ability , user : User , ... args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < void > {
34+ export async function authorize < Ability extends BouncerAbility < any > , User extends Record < string , any > = Ability extends BouncerAbility < infer U > ? U : never > ( bouncerAbility : Ability , user : User | null , ...args : BouncerArgs < Ability > ) : Promise < void > {
3535 const response = await bouncerAbility . execute ( user , ...args )
3636 const normalized = normalizeAuthorizationResponse ( response )
3737 if ( ! normalized . authorized ) {
0 commit comments