diff --git a/CHANGELOG.md b/CHANGELOG.md index b90c569..37f0675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ +## [0.5.1](https://github.com/dennemark/prisma-extension-casl/compare/0.5.0...0.5.1) (2024-08-08) + + +### Bug Fixes + +* :bug: alternative way to alter abilities on prisma client ([a9e22d9](https://github.com/dennemark/prisma-extension-casl/commit/a9e22d91905d05de46809c7f2ecf67e6c54a1564)) + ## [0.5.0](https://github.com/dennemark/prisma-extension-casl/compare/0.4.3...0.5.0) (2024-08-08) diff --git a/dist/index.d.mts b/dist/index.d.mts index 939a84e..cac2390 100644 --- a/dist/index.d.mts +++ b/dist/index.d.mts @@ -41,17 +41,221 @@ declare function useCaslAbilities(getAbilityFactory: () => AbilityBuilder (extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>) => _prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, { - result: {}; - model: {}; - query: {}; - client: {}; - }, {}>; + $casl: () => (extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>) => { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + } & { + $casl: unknown; + } & { + [K: symbol]: { + ctx: { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + }; + }; + } & { + $casl(extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>): { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + } & { + $casl: unknown; + } & { + [K: symbol]: { + ctx: { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + }; + }; + } & any & { + name?: string; + $name?: string; + $parent?: unknown; + }; + } & { + name?: string; + $name?: string; + $parent?: unknown; + }; }; }; }; diff --git a/dist/index.d.ts b/dist/index.d.ts index 939a84e..cac2390 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -41,17 +41,221 @@ declare function useCaslAbilities(getAbilityFactory: () => AbilityBuilder (extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>) => _prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, { - result: {}; - model: {}; - query: {}; - client: {}; - }, {}>; + $casl: () => (extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>) => { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + } & { + $casl: unknown; + } & { + [K: symbol]: { + ctx: { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + }; + }; + } & { + $casl(extendFactory: (factory: AbilityBuilder>) => AbilityBuilder>): { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + } & { + $casl: unknown; + } & { + [K: symbol]: { + ctx: { + $connect?: (() => Promise) | undefined; + $disconnect?: (() => Promise) | undefined; + $transaction?: { +

[]>(arg: [...P], options?: { + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise<_prisma_client_runtime_library.UnwrapTuple

>; + (fn: (client: Omit<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">) => Promise, options?: { + maxWait?: number; + timeout?: number; + isolationLevel?: "Serializable" | undefined; + } | undefined): Promise; + } | undefined; + $extends?: _prisma_client_runtime_library.ExtendsHook<"extends", Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, Prisma.TypeMap<_prisma_client_runtime_library.InternalArgs & _prisma_client_runtime_library.DefaultArgs, Prisma.PrismaClientOptions>, {}> | undefined; + } & { + [x: symbol]: { + types: { + payload: any; + operations: { + $executeRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $executeRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + $queryRawUnsafe: { + args: [query: string, ...values: any[]]; + result: any; + }; + $queryRaw: { + args: [query: TemplateStringsArray | Prisma.Sql, ...values: any[]]; + result: any; + }; + }; + }; + }; + $executeRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $executeRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRaw: (query: TemplateStringsArray | Prisma.Sql, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + $queryRawUnsafe: (query: string, ...values: any[]) => _prisma_client_runtime_library.PrismaPromise; + user: _prisma_client_runtime_library.DynamicModelExtensionThis, "User", _prisma_client_runtime_library.DefaultArgs, {}>; + topic: _prisma_client_runtime_library.DynamicModelExtensionThis, "Topic", _prisma_client_runtime_library.DefaultArgs, {}>; + thread: _prisma_client_runtime_library.DynamicModelExtensionThis, "Thread", _prisma_client_runtime_library.DefaultArgs, {}>; + post: _prisma_client_runtime_library.DynamicModelExtensionThis, "Post", _prisma_client_runtime_library.DefaultArgs, {}>; + } & { + $parent: _prisma_client_runtime_library.Optional<_prisma_client_runtime_library.DynamicClientExtensionThis, Prisma.TypeMapCb, _prisma_client_runtime_library.DefaultArgs, {}>, "$on" | "$connect" | "$disconnect" | "$use" | "$transaction" | "$extends">; + }; + }; + } & any & { + name?: string; + $name?: string; + $parent?: unknown; + }; + } & { + name?: string; + $name?: string; + $parent?: unknown; + }; }; }; }; diff --git a/dist/index.js b/dist/index.js index 8af0524..a4860ac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1182,7 +1182,16 @@ function filterQueryResults(result, mask, abilities, model) { // src/index.ts function useCaslAbilities(getAbilityFactory) { return import_client2.Prisma.defineExtension((client) => { - const caslExtension = (getAbility) => ({ + let getAbilities = () => getAbilityFactory(); + return client.$extends({ + name: "prisma-extension-casl", + client: { + $casl(extendFactory) { + const ctx = import_client2.Prisma.getExtensionContext(this); + getAbilities = () => extendFactory(getAbilityFactory()); + return ctx; + } + }, query: { $allModels: { async $allOperations({ args, query, model, operation, ...rest }) { @@ -1204,7 +1213,8 @@ function useCaslAbilities(getAbilityFactory) { return query(args); } perf?.mark("prisma-casl-extension-0"); - const abilities = getAbility().build(); + const abilities = getAbilities().build(); + getAbilities = () => getAbilityFactory(); perf?.mark("prisma-casl-extension-1"); const caslQuery = applyCaslToQuery(operation, args, abilities, model); perf?.mark("prisma-casl-extension-2"); @@ -1233,18 +1243,6 @@ function useCaslAbilities(getAbilityFactory) { } } }); - return client.$extends({ - name: "prisma-extension-casl", - ...caslExtension(getAbilityFactory), - client: { - $casl(extendFactory) { - return client.$extends({ - name: "prisma-extension-casl-customized", - ...caslExtension(() => extendFactory(getAbilityFactory())) - }); - } - } - }); }); } // Annotate the CommonJS export names for ESM import in node: diff --git a/dist/index.mjs b/dist/index.mjs index 5c29b44..c23ab8d 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1157,7 +1157,16 @@ function filterQueryResults(result, mask, abilities, model) { // src/index.ts function useCaslAbilities(getAbilityFactory) { return Prisma2.defineExtension((client) => { - const caslExtension = (getAbility) => ({ + let getAbilities = () => getAbilityFactory(); + return client.$extends({ + name: "prisma-extension-casl", + client: { + $casl(extendFactory) { + const ctx = Prisma2.getExtensionContext(this); + getAbilities = () => extendFactory(getAbilityFactory()); + return ctx; + } + }, query: { $allModels: { async $allOperations({ args, query, model, operation, ...rest }) { @@ -1179,7 +1188,8 @@ function useCaslAbilities(getAbilityFactory) { return query(args); } perf?.mark("prisma-casl-extension-0"); - const abilities = getAbility().build(); + const abilities = getAbilities().build(); + getAbilities = () => getAbilityFactory(); perf?.mark("prisma-casl-extension-1"); const caslQuery = applyCaslToQuery(operation, args, abilities, model); perf?.mark("prisma-casl-extension-2"); @@ -1208,18 +1218,6 @@ function useCaslAbilities(getAbilityFactory) { } } }); - return client.$extends({ - name: "prisma-extension-casl", - ...caslExtension(getAbilityFactory), - client: { - $casl(extendFactory) { - return client.$extends({ - name: "prisma-extension-casl-customized", - ...caslExtension(() => extendFactory(getAbilityFactory())) - }); - } - } - }); }); } export { diff --git a/package.json b/package.json index 36a26c1..38714ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prisma-extension-casl", - "version": "0.5.0", + "version": "0.5.1", "description": "Enforce casl abilities on prisma client ", "main": "dist/index.js", "types": "dist/index.d.ts",