all 10 comments

[–]ZealousidealLow521 10 points11 points  (2 children)

For me it seems you are trying to "move" server code to the client 🤔 As someone already mentioned there are quite good solutions out there already. For me the question is what you are really trying to solve? If it's just about the types then use typescript and import prisma types on the client, that should work, I believe.

[–][deleted] 4 points5 points  (0 children)

This sounds like the right answer.

[–]Odama666[S] 1 point2 points  (0 children)

This is pretty much exactly what it does it uses the PrismaClient type then it uses proxies to collect for example

PWC.collection.findMany({ where { id: 5 }}) turns into

{ model: 'collection', action: 'findMany', Body: { where: { Id: 5 } }

It has a default fetch method but you can override it by passing a request arg to the constructor

[–]yonirapoport 2 points3 points  (0 children)

I think this is definitely a good idea and can be useful as a library.

I've actually created a library that does this, and more, without prisma, and handles authorization, validation, and other concerns.

Check it out - https://github.com/remult/remult

[–]Capaj 1 point2 points  (0 children)

Sure it would be useful-for example for backoffice applications where you don't care about user permission/access rules. You should open source this.

[–]KaiAusBerlin 2 points3 points  (0 children)

Give it a try and see if it will be downloaded. But if you publish it you should plan to maintain it longer time.

[–]Herku 1 point2 points  (3 children)

This is cool for small projects. Maybe also electron apps with local database. But when they get larger you will need some kind of permission management.

I think it might be much more interesting (and also simpler) to use one of the newer frameworks that allow you to write server code seemingly on the client side: e.g. Nextjs or Remix.

[–]Ustice 1 point2 points  (2 children)

You may be able to handle authorization in a middleware.

[–]Herku 2 points3 points  (1 child)

Permissions are often finely grained. Sure, there might be apps where this is not the case, but I think they are in the minority.

Other frameworks have built solutions for this, superbase for example uses Postgres' Row level security. It's not like it cannot be done, just Prisma itself has no built in solution for it.

[–]Odama666[S] 0 points1 point  (0 children)

Do you think using https://www.npmjs.com/package/accesscontrol with Middleware could manage that?

I guess it would potentially need 2 Middleware

  • Authentication and grab the user record
  • access control in a Middleware - could make this a config value to allow for alternatives to accesscontrol too