zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.04k stars 85 forks source link

[Feature Request] Model-Level CRUD Hooks #1128

Open andrewpeters9 opened 6 months ago

andrewpeters9 commented 6 months ago

Is your feature request related to a problem? Please describe.

Example Usecases:

Describe the solution you'd like

Potential Challenges:

Comment from @ymc9

This is some thought background about access conrol. As for CRUD hooks, I fully agree with you that implementing with Prisma client extensions can be quite challenging given the flexibility of nesting - it's very easy to have a leaky implementation. I think it's a good idea that we "reimplement" some kind of hook at the TS-API land, like allowing you to provide simple callbacks when calling enhance (model + operation + action), and the API internally deals with traversing nesting, and probably also guarantees a transaction boundary.

genu commented 2 months ago

For an idea of how this would work at a high level, have a look at keystone-js, which is also built on top of Prisma.

They're docs explain the implementation pretty well: https://keystonejs.com/docs/guides/hooks and the hooks api: https://keystonejs.com/docs/config/hooks