refactor: replace @prisma/client/runtime imports with public API (#23087)
- Replace PrismaClientKnownRequestError and other error classes with Prisma namespace equivalents - Remove internal DefaultArgs and InternalArgs type imports from Prisma extensions - Ensure all error handling uses stable public API exports - Maintain compatibility with future Prisma versions by avoiding runtime dependencies Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
6 files changed
+29
-38
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export function getRequestedSlugError(error: unknown, requestedSlug: string) {
|
||||
let message = `Unknown error`;
|
||||
@@ -6,7 +6,7 @@ export function getRequestedSlugError(error: unknown, requestedSlug: string) {
|
||||
// This covers the edge case if an unpublished team takes too long to publish
|
||||
// and another team gets the requestedSlug first.
|
||||
// https://www.prisma.io/docs/reference/api-reference/error-reference#p2002
|
||||
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
statusCode = 400;
|
||||
message = `It seems like the requestedSlug: '${requestedSlug}' is already taken. Please contact support at [email protected] so we can resolve this issue.`;
|
||||
} else if (error instanceof Error) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Account, IdentityProvider, Prisma, User, VerificationToken } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
|
||||
import type { Account, IdentityProvider, User, VerificationToken } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { Awaitable } from "next-auth";
|
||||
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
@@ -86,7 +86,7 @@ export default function CalComAdapter(prismaClient: PrismaClient): CalComAdapter
|
||||
} catch (error) {
|
||||
// If token already used/deleted, just return null
|
||||
// https://www.prisma.io/docs/reference/api-reference/error-reference#p2025
|
||||
if (error instanceof PrismaClientKnownRequestError) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
if (error.code === "P2025") return null;
|
||||
}
|
||||
throw error;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { DefaultArgs, InternalArgs } from "@prisma/client/runtime/library";
|
||||
|
||||
export function excludeLockedUsersExtension() {
|
||||
return Prisma.defineExtension({
|
||||
@@ -35,11 +34,11 @@ function safeJSONStringify(x: any) {
|
||||
|
||||
async function excludeLockedUsers(
|
||||
args:
|
||||
| Prisma.UserFindUniqueArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.UserFindFirstArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.UserFindManyArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.UserFindUniqueOrThrowArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.UserFindFirstOrThrowArgs<InternalArgs & DefaultArgs>,
|
||||
| Prisma.UserFindUniqueArgs
|
||||
| Prisma.UserFindFirstArgs
|
||||
| Prisma.UserFindManyArgs
|
||||
| Prisma.UserFindUniqueOrThrowArgs
|
||||
| Prisma.UserFindFirstOrThrowArgs,
|
||||
query: <T>(args: T) => Promise<unknown>
|
||||
) {
|
||||
args.where = args.where || {};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { DefaultArgs, InternalArgs } from "@prisma/client/runtime/library";
|
||||
|
||||
export function excludePendingPaymentsExtension() {
|
||||
return Prisma.defineExtension({
|
||||
@@ -27,11 +26,11 @@ export function excludePendingPaymentsExtension() {
|
||||
|
||||
async function excludePendingPayments(
|
||||
args:
|
||||
| Prisma.TeamFindUniqueArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindFirstArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindManyArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindUniqueOrThrowArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindFirstOrThrowArgs<InternalArgs & DefaultArgs>,
|
||||
| Prisma.TeamFindUniqueArgs
|
||||
| Prisma.TeamFindFirstArgs
|
||||
| Prisma.TeamFindManyArgs
|
||||
| Prisma.TeamFindUniqueOrThrowArgs
|
||||
| Prisma.TeamFindFirstOrThrowArgs,
|
||||
query: <T>(args: T) => Promise<unknown>
|
||||
) {
|
||||
args.where = args.where || {};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import { DailyLocationType } from "@calcom/app-store/locations";
|
||||
import { getDefaultLocations } from "@calcom/lib/server/getDefaultLocations";
|
||||
@@ -139,7 +138,7 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
||||
return { eventType };
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
if (e instanceof PrismaClientKnownRequestError) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
if (e.code === "P2002" && Array.isArray(e.meta?.target) && e.meta?.target.includes("slug")) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "URL Slug already exists for given user." });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user