From a6da0ab0f46891eb8b9e422cced76fe718cff8b5 Mon Sep 17 00:00:00 2001 From: Lucian Buzzo Date: Fri, 8 Dec 2023 17:50:12 +0000 Subject: [PATCH] fix: update to work with latest prisma client version Signed-off-by: Lucian Buzzo --- src/expressions.ts | 6 +++++- src/index.ts | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/expressions.ts b/src/expressions.ts index de94ad9..81c0cc4 100644 --- a/src/expressions.ts +++ b/src/expressions.ts @@ -4,7 +4,11 @@ import random from "lodash/random"; import matches from "lodash/matches"; import { Parser } from "node-sql-parser"; import { escapeIdentifier, escapeLiteral } from "./escape"; -import { RuntimeDataModel } from "@prisma/client/runtime/library"; +import { defineDmmfProperty } from "@prisma/client/runtime/library"; + +// This is black magic to get the runtime data model from the Prisma client +// It's not exported, so we need to use some type infiltration to get it +export type RuntimeDataModel = Parameters[1]; const PRISMA_NUMERIC_TYPES = ["Int", "BigInt", "Float", "Decimal"]; diff --git a/src/index.ts b/src/index.ts index ee8996d..b1e6378 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,14 @@ import { Prisma, PrismaClient } from "@prisma/client"; -import { RuntimeDataModel } from "@prisma/client/runtime/library"; import difference from "lodash/difference"; import flatMap from "lodash/flatMap"; import map from "lodash/map"; import toPairs from "lodash/toPairs"; import * as crypto from "crypto"; -import { Expression, expressionToSQL } from "./expressions"; +import { Expression, expressionToSQL, RuntimeDataModel } from "./expressions"; const VALID_OPERATIONS = ["SELECT", "UPDATE", "INSERT", "DELETE"] as const; -type Operation = typeof VALID_OPERATIONS[number]; +type Operation = (typeof VALID_OPERATIONS)[number]; export type Models = Prisma.ModelName; interface ClientOptions { @@ -70,7 +69,11 @@ const hashWithPrefix = (prefix: string, abilityName: string) => { }; // Sanitize a single string by ensuring the it has only lowercase alpha characters and underscores -const sanitizeSlug = (slug: string) => slug.toLowerCase().replace("-", "_").replace(/[^a-z0-9_]/gi, ""); +const sanitizeSlug = (slug: string) => + slug + .toLowerCase() + .replace("-", "_") + .replace(/[^a-z0-9_]/gi, ""); export const createAbilityName = (model: string, ability: string) => { return sanitizeSlug(hashWithPrefix("yates_ability_", `${model}_${ability}`));