Show HN: Kysely-access-control (permissions at the query building layer)
Hi there!<p>I just published my first (hopefully of many) personal open source project to be used by others.<p>There&#x27;s 2 packages:
- The lower level kysely-access-control (<a href="https:&#x2F;&#x2F;github.com&#x2F;ben-pr-p&#x2F;kysely-utils&#x2F;tree&#x2F;main&#x2F;packages&#x2F;kysely-access-control">https:&#x2F;&#x2F;github.com&#x2F;ben-pr-p&#x2F;kysely-utils&#x2F;tree&#x2F;main&#x2F;packages&#x2F;...</a>), which implements a callback that you can return `Allow&#x2F;Deny&#x2F;Omit` + `[Allow, where]` for<p>- A higher level kysely-grants (<a href="https:&#x2F;&#x2F;github.com&#x2F;ben-pr-p&#x2F;kysely-utils&#x2F;tree&#x2F;main&#x2F;packages&#x2F;kysely-grants">https:&#x2F;&#x2F;github.com&#x2F;ben-pr-p&#x2F;kysely-utils&#x2F;tree&#x2F;main&#x2F;packages&#x2F;...</a>) that implements Postgres like grants on top of kysely<p>The idea grew out of frustration I&#x27;ve had implementing permissions in the past.<p>On some projects, I&#x27;ve implemented it each time data is supposed to be accessed, which has meant the developer implementing the route needs to know about all the permissions considerations accessing that data.<p>On other projects, I&#x27;ve implemented it at the database layer (in Postgres). That&#x27;s been a generally decent experience, but gets hard to manage when you want the same user to have different permissions depending on the context. Additionally, it restricts how you can access and cache calls to the database, since you need to run (and your cache key depends on) `set_config` calls with the relevant access details on each statement request.<p>After this, I&#x27;m planning on writing and publishing an executor for Kysely that can automatically cache database queries. Since this access control plugin modifies the actual Kysely internal operation node, that plugin will properly cache results per user. I&#x27;m also hoping to write a plugin that can automatically invalidate the cache from wal2json results.<p>Feedback is super appreciated and sought after! This is my first external facing npm package, and I found the process a bit tricky to execute.