diff --git a/package.json b/package.json index db9dec6..893ec8f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/prisma/createPrismaAddWhere.ts b/src/prisma/createPrismaAddWhere.ts index db6cabb..2267890 100644 --- a/src/prisma/createPrismaAddWhere.ts +++ b/src/prisma/createPrismaAddWhere.ts @@ -1,16 +1,14 @@ -import { PrismaClient } from "@prisma/client"; +import { PrismaClientCustom } from "./types"; -export const prismaAddGlobalWhere = (prisma: PrismaClient, where: object) => { +export const prismaAddGlobalWhere = ( + 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>, diff --git a/src/prisma/onPrisma.ts b/src/prisma/onPrisma.ts index 26f30ed..67a3ab9 100644 --- a/src/prisma/onPrisma.ts +++ b/src/prisma/onPrisma.ts @@ -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 = ( PrismaClientNative: PrismaClient, options?: onPrismaParamsOptios, ) => { - if ((global as Global).prisma) return (global as Global).prisma; + if ((global as Global).prisma) + return (global as Global).prisma; if (options?.whereGlobal) return prismaAddGlobalWhere(new PrismaClientNative(), options?.whereGlobal); @@ -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).prisma || new PrismaClientNative(); return { prisma }; }; diff --git a/src/prisma/types.ts b/src/prisma/types.ts index 951d59b..032853c 100644 --- a/src/prisma/types.ts +++ b/src/prisma/types.ts @@ -1,3 +1,9 @@ +export type PrismaClientCustom = new () => any; + +export interface Global { + prisma?: PrismaClient; +} + export interface onPrismaParamsOptios { whereGlobal: object; } diff --git a/src/types.ts b/src/types.ts index 358a622..3c9c346 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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.