Skip to content

Commit

Permalink
refactor: 🚚 move functions to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
dennemark committed Jul 26, 2024
1 parent 8ece2c2 commit 465703b
Show file tree
Hide file tree
Showing 21 changed files with 1,025 additions and 934 deletions.
29 changes: 12 additions & 17 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
import { Prisma } from '@prisma/client';
import { PureAbility, AbilityTuple } from '@casl/ability';
import { PrismaQuery } from '@casl/prisma';

type DefaultCaslAction = "create" | "read" | "update" | "delete";
type PrismaCaslOperation = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' | 'findFirst' | 'findFirstOrThrow' | 'findMany' | 'findUnique' | 'findUniqueOrThrow' | 'aggregate' | 'count' | 'groupBy' | 'update' | 'updateMany' | 'delete' | 'deleteMany';
declare const caslOperationDict: Record<PrismaCaslOperation, {
action: DefaultCaslAction;
dataQuery: boolean;
whereQuery: boolean;
includeSelectQuery: boolean;
}>;
/**
* enrich a prisma client to check for CASL abilities even in nested queries
*
* `client.$extends(useCaslAbilities(build()))`
*
* https://casl.js.org/v6/en/package/casl-prisma
*
*
* @param abilities CASL prisma abilities
* @returns enriched prisma client
*/
declare const useCaslAbilities: (abilities: PureAbility<AbilityTuple, PrismaQuery>) => (client: any) => {
$extends: {
extArgs: _prisma_client_runtime_library.InternalArgs<unknown, unknown, {}, unknown>;
};
};
declare function applyCaslToQuery(operation: any, args: any, abilities: PureAbility<AbilityTuple, PrismaQuery>, model: Prisma.ModelName): any;
declare function applyDataQuery(abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, action: string, model: string): any;
declare function applyWhereQuery(abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, action: string, model: string, relation?: string): any;
declare const applySelectPermittedFields: (abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, model: string) => any;
declare const applyIncludeSelectQuery: (abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, model: string) => any;
declare function capitalizeFirstLetter(string: string): string;
declare function isSubset(obj1: any, obj2: any): boolean;

export { type PrismaCaslOperation, applyCaslToQuery, applyDataQuery, applyIncludeSelectQuery, applySelectPermittedFields, applyWhereQuery, capitalizeFirstLetter, caslOperationDict, isSubset, useCaslAbilities };
export { useCaslAbilities };
29 changes: 12 additions & 17 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
import { Prisma } from '@prisma/client';
import { PureAbility, AbilityTuple } from '@casl/ability';
import { PrismaQuery } from '@casl/prisma';

type DefaultCaslAction = "create" | "read" | "update" | "delete";
type PrismaCaslOperation = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' | 'findFirst' | 'findFirstOrThrow' | 'findMany' | 'findUnique' | 'findUniqueOrThrow' | 'aggregate' | 'count' | 'groupBy' | 'update' | 'updateMany' | 'delete' | 'deleteMany';
declare const caslOperationDict: Record<PrismaCaslOperation, {
action: DefaultCaslAction;
dataQuery: boolean;
whereQuery: boolean;
includeSelectQuery: boolean;
}>;
/**
* enrich a prisma client to check for CASL abilities even in nested queries
*
* `client.$extends(useCaslAbilities(build()))`
*
* https://casl.js.org/v6/en/package/casl-prisma
*
*
* @param abilities CASL prisma abilities
* @returns enriched prisma client
*/
declare const useCaslAbilities: (abilities: PureAbility<AbilityTuple, PrismaQuery>) => (client: any) => {
$extends: {
extArgs: _prisma_client_runtime_library.InternalArgs<unknown, unknown, {}, unknown>;
};
};
declare function applyCaslToQuery(operation: any, args: any, abilities: PureAbility<AbilityTuple, PrismaQuery>, model: Prisma.ModelName): any;
declare function applyDataQuery(abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, action: string, model: string): any;
declare function applyWhereQuery(abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, action: string, model: string, relation?: string): any;
declare const applySelectPermittedFields: (abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, model: string) => any;
declare const applyIncludeSelectQuery: (abilities: PureAbility<AbilityTuple, PrismaQuery>, args: any, model: string) => any;
declare function capitalizeFirstLetter(string: string): string;
declare function isSubset(obj1: any, obj2: any): boolean;

export { type PrismaCaslOperation, applyCaslToQuery, applyDataQuery, applyIncludeSelectQuery, applySelectPermittedFields, applyWhereQuery, capitalizeFirstLetter, caslOperationDict, isSubset, useCaslAbilities };
export { useCaslAbilities };
Loading

0 comments on commit 465703b

Please sign in to comment.