From 29f2d9035ee96be1dedc1f8dc23d91e5ee6dd5e4 Mon Sep 17 00:00:00 2001 From: Sergii Stotskyi Date: Wed, 27 Mar 2024 12:20:20 +0200 Subject: [PATCH] fix: gets rid of dist imported types which cannot be resolved at runtime (#895) --- packages/casl-mongoose/src/accessibleBy.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/casl-mongoose/src/accessibleBy.ts b/packages/casl-mongoose/src/accessibleBy.ts index 8115d3cc4..35c6ebcca 100644 --- a/packages/casl-mongoose/src/accessibleBy.ts +++ b/packages/casl-mongoose/src/accessibleBy.ts @@ -1,5 +1,4 @@ -import { AnyMongoAbility, Generics, SubjectType } from '@casl/ability'; -import { ToAbilityTypes } from '@casl/ability/dist/types/types'; +import { AnyMongoAbility, Generics, SubjectType, Abilities, AbilityTuple, ExtractSubjectType } from '@casl/ability'; import { rulesToQuery } from '@casl/ability/extra'; function convertToMongoQuery(rule: AnyMongoAbility['rules'][number]) { @@ -23,12 +22,16 @@ export class AccessibleRecords { } } +type SubjectTypes = T extends AbilityTuple + ? ExtractSubjectType + : never; + /** * Returns accessible records Mongo query per record type (i.e., entity type) based on provided Ability and action. */ export function accessibleBy( ability: T, action: Parameters[0] = 'read' -): AccessibleRecords['abilities']>[1]> { +): AccessibleRecords['abilities']>> { return new AccessibleRecords(ability, action); }