47ng / prisma-field-encryption

Transparent field-level encryption at rest for Prisma
https://github.com/franky47/prisma-field-encryption-sandbox
MIT License
224 stars 27 forks source link

Feature request: @prisma/client 5.0.0 peer dependency #69

Closed greeksolid closed 11 months ago

greeksolid commented 11 months ago

Would it be possible to update the peerDependencies to include latest @prisma/client release or is there a breaking change?

franky47 commented 11 months ago

See https://github.com/47ng/prisma-field-encryption/issues/63#issuecomment-1641637805, there's a beta release for Prisma v5 with the client extension mechanism.

Please give it a try and let me know if it works for you so I can merge PR #66 which includes this change.

greeksolid commented 11 months ago

Yes, it works perfectly fine on my end and also passes type checking with the 'as PrismaClient' cast. Thanks!

franky47 commented 11 months ago

If you're only using the extension mechanism, this cast should not be needed, could you confirm that it works without please?

It's only needed in the integration tests of this library to account for both mechanism being used by the same test codebase.

greeksolid commented 11 months ago

In my project it seems that the cast is required. I 'll try to reproduce it in a barebones project and get back to you.

franky47 commented 11 months ago

For reference, I've opened a bug report in the Prisma repository about typing extended clients, see https://github.com/prisma/prisma/issues/20326

greeksolid commented 11 months ago

Sorry man false alarm! I am using Next.js and initialize the client like this, so I had globalForPrisma.prisma explicitly typed as PrismaClient | undefined.

I changed it to this and get no type errors anymore.

import { PrismaClient } from "@prisma/client";
import { fieldEncryptionExtension } from "prisma-field-encryption";

const createPrismaClient = () => {
  const globalClient = new PrismaClient({
    log: ["warn", "query", "error"],
  });
  return globalClient.$extends(fieldEncryptionExtension());
};

const globalForPrisma = globalThis as unknown as {
  prisma: ReturnType<typeof createPrismaClient> | undefined;
};

export const prisma = globalForPrisma.prisma ?? createPrismaClient();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
franky47 commented 11 months ago

Released in 1.5.0.