Prisma Client Extension Audit Trail
A soft delete and audit trail extension for Prisma 7, which removed the $use client middleware API in 7.0.0 and left client extensions as the only interception point. It splits the work across two components because neither can do both jobs: query.$allModels.$allOperations injects deletedAt: null into the filtered read operations and records writes to an audit sink, while model.$allModels rewrites delete and deleteMany into an update through Prisma.getExtensionContext(this), preserving the row and count return shapes. The actor is bound per request rather than globally, since $extends returns a new proxy client instead of mutating the receiver, so a module-scoped extended client would attribute every write in the process to whoever was in scope at import time. Audit rows are written through the unextended base client, which removes the recursion class of bug rather than policing it with a model name guard. The caveats that actually bite migrators are documented inline: query extensions never fire for nested reads or writes, so a nested create is invisible and an include of a soft-delete model is unfiltered, and $connect is not guaranteed to exist on an extended client.
npx shadcn@latest add https://ui.aryank.space/r/prisma-client-extension-audit.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
prisma.user.delete() destroys the row. When the support ticket arrives asking what happened to this account, there is no row, no history, and no answer: the data and the evidence deleted each other.