Skip to content

Commit

Permalink
fix: update to work with latest prisma client version
Browse files Browse the repository at this point in the history
Signed-off-by: Lucian Buzzo <lucian.buzzo@gmail.com>
  • Loading branch information
LucianBuzzo committed Dec 11, 2023
1 parent cdb1d88 commit a6da0ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof defineDmmfProperty>[1];

const PRISMA_NUMERIC_TYPES = ["Int", "BigInt", "Float", "Decimal"];

Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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}`));
Expand Down

0 comments on commit a6da0ab

Please sign in to comment.