omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers
MIT License
675 stars 34 forks source link

feat(shield): withShield optional string path #78

Closed imsanchez closed 1 year ago

imsanchez commented 1 year ago

This is https://github.com/omar-dulaimi/prisma-trpc-generator/pull/65 but addressing @omar-dulaimi's comments of consistency with string | boolean pattern.

cc: @lottamus

Description

When withShield is true,

generator trpc {
  ...
  withShield = true
}

We generate a boilerplate configuration using allow for all procedures and we overwrite this file on each generation.

It looks something like this:

import { shield, allow } from 'trpc-shield';
import { Context } from '../../context';

export const permissions = shield<Context>({
  query: {
    aggregate: allow,
    ...
  },
  mutation: {
    create: allow,
    ...
  },
});

This pull request updates the option withShield to allow a string path to your own tRPC Shield to use as the permission layer.

Similarly to withMiddleware, this will extend withShield to allow either a boolean or a string path.

When withShield is a string path:

generator trpc {
  ...
  withShield = "../../libs/shield"
}

The routers/helpers/createRouter.ts will use the path instead:

import { permissions } from "../../libs/shield";
omar-dulaimi commented 1 year ago

Hey @imsanchez

Thanks for the PR, I'll take a look very soon

imsanchez commented 1 year ago

Ready for your approval @omar-dulaimi

omar-dulaimi commented 1 year ago

Released in https://github.com/omar-dulaimi/prisma-trpc-generator/releases/tag/1.4.0

Thank you @imsanchez Keep them coming!