Skip to content

Commit

Permalink
[version] 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
leomerida15 committed Feb 4, 2024
1 parent 2cec1a6 commit aa19260
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
12 changes: 5 additions & 7 deletions src/prisma/createPrismaAddWhere.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { PrismaClient } from "@prisma/client";
import { PrismaClientCustom } from "./types";

export const prismaAddGlobalWhere = (prisma: PrismaClient, where: object) => {
export const prismaAddGlobalWhere = <PrismaClient extends PrismaClientCustom>(
prisma: PrismaClient,
where: object,
) => {
for (const KeyModel in prisma) {
if (!Object.prototype.hasOwnProperty.call(prisma, KeyModel)) continue;

if (/[$_]*/i.test(KeyModel)) return;

console.clear();
console.log("keys");
console.log("Object.keys(prisma)", Object.keys(prisma));
console.log(Object.keys(prisma[KeyModel as keyof PrismaClient]));

// @ts-ignore
prisma[KeyModel as keyof PrismaClient].findFirst = (
obj?: Record<"where", any>,
Expand Down
16 changes: 6 additions & 10 deletions src/prisma/onPrisma.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// import { prismaAddGlobalWhere } from "./function/createPrismaAddWhere";
import { PrismaClient } from "@prisma/client";
import { onPrismaParamsOptios } from "./types";
import { PrismaClientCustom, onPrismaParamsOptios, Global } from "./types";
import { prismaAddGlobalWhere } from "./createPrismaAddWhere";

interface Global {
prisma?: PrismaClient;
}

export const onPrisma = (
export const onPrisma = <PrismaClient extends PrismaClientCustom>(
PrismaClientNative: PrismaClient,
options?: onPrismaParamsOptios,
) => {
if ((global as Global).prisma) return (global as Global).prisma;
if ((global as Global<PrismaClient>).prisma)
return (global as Global<PrismaClient>).prisma;

if (options?.whereGlobal)
return prismaAddGlobalWhere(new PrismaClientNative(), options?.whereGlobal);
Expand All @@ -20,7 +15,8 @@ export const onPrisma = (
(global as any).prisma = new PrismaClientNative();
}

const prisma = (global as Global).prisma || new PrismaClientNative();
const prisma =
(global as Global<PrismaClient>).prisma || new PrismaClientNative();

return { prisma };
};
6 changes: 6 additions & 0 deletions src/prisma/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type PrismaClientCustom = new () => any;

export interface Global<PrismaClient extends PrismaClientCustom> {
prisma?: PrismaClient;
}

export interface onPrismaParamsOptios {
whereGlobal: object;
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ResolverKeys } from "./resolvers/types";

export * from "./resolvers/types";
export * from "./docs/types";
export type * from "./httpStatus";
export * from "./httpStatus";

/**
* Configuration object for the Rocket-kit.
Expand Down

0 comments on commit aa19260

Please sign in to comment.