I'm using a great extension that helps eliminate a lot of repetitive code in my application. It works well, but I want to change the response format from [Data[], Meta] to { docs: Data[], meta: Meta }.
I know I could wrap the response using a custom function, but I’d prefer to handle this directly within the Prisma client extension. That way, the rest of the team won’t have to remember to apply a wrapper manually. It will ensure consistency and reduce the chance of mistakes.
Here's what I tried:
const paginate = createPaginator({
pages: {
includePageCount: true,
},
});
const prismaClient = new PrismaClient().$extends({
model: {
$allModels: {
paginate() {
return paginate(); // I tried passing the args from paginate and this, but no luck
},
},
},
});
However, this results in the following error:
TypeError: Cannot read properties of undefined (reading 'findMany')
at /<my_workspace>/node_modules/.pnpm/prisma-extension-pagination@0.7.5_@prisma+client@6.8.2_prisma@6.8.2_typescript@5.8.3__typescript@5.8.3_/node_modules/prisma-extension-pagination/dist/page-number.js:22:19
I also attempted to extend the withPages method but encountered the same issue. How can I modify the response shape directly within the Prisma client extension so it returns { docs, meta } instead of an array?
I'm using a great extension that helps eliminate a lot of repetitive code in my application. It works well, but I want to change the response format from
[Data[], Meta]to{ docs: Data[], meta: Meta }.I know I could wrap the response using a custom function, but I’d prefer to handle this directly within the Prisma client extension. That way, the rest of the team won’t have to remember to apply a wrapper manually. It will ensure consistency and reduce the chance of mistakes.
Here's what I tried:
However, this results in the following error:
I also attempted to extend the
withPagesmethod but encountered the same issue. How can I modify the response shape directly within the Prisma client extension so it returns{ docs, meta }instead of an array?