Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library is broken with 4.16.0 #91

Closed
jakeleventhal opened this issue Jun 20, 2023 · 3 comments
Closed

Library is broken with 4.16.0 #91

jakeleventhal opened this issue Jun 20, 2023 · 3 comments

Comments

@jakeleventhal
Copy link

prisma/prisma#19863

@arthurfiorette
Copy link
Owner

Hey @jakeleventhal, thanks for your report, can you provide your prisma schema configuration? Like generators and preview features?

@jakeleventhal
Copy link
Author

// Docs: https://pris.ly/d/prisma-schema

generator client {
  provider        = "prisma-client-js"
  output          = "../../../../node_modules/@prisma/client/ecominate"
  previewFeatures = ["clientExtensions", "fullTextSearch", "jsonProtocol"]
  binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator json {
  provider     = "prisma-json-types-generator"
  namespace    = "EcominatePrismaJsonTypes"
  clientOutput = "../../../../node_modules/@prisma/client/ecominate"
}

/// Data that is used to control global, application-level logic across all users.
model AppData {
  id String @id @default(uuid())

  /// Whether or not the app is in maintenance mode.
  maintenance    Boolean @default(false)
  /// [StripeCustomerPortalConfig]
  /// The Stripe customer portal config.
  customerPortal Json?
  /// [StripeWebhookConfig]
  /// The Stripe webhook config.
  stripeWebhook  Json?
}
import Stripe from 'stripe';

declare global {
  namespace EcominatePrismaJsonTypes {
    interface StripeCustomerPortalConfig {
      id: string;
      config: Stripe.BillingPortal.ConfigurationCreateParams;
    }

    interface StripeWebhookConfig {
      id: string;
      config: Stripe.WebhookEndpointCreateParams;
    }
  }
}
import './prismaJsonTypesNamespace';

import { Prisma, PrismaClient } from '@prisma/client/ecominate';

const client = (url: string | undefined) =>
  new PrismaClient(url ? { datasources: { db: { url } } } : undefined).$extends({
    model: {
      $allModels: {
        async exists<T>(this: T, where: Prisma.Args<T, 'findFirst'>['where']): Promise<boolean> {
          const context = Prisma.getExtensionContext(this);
          const result = await (context as any).count({ where });
          return result > 0;
        }
      }
    }
  });

export type ExtendedPrismaClient = ReturnType<typeof client>;

// Export the prisma client
export const getPrismaClient = (url?: string): ExtendedPrismaClient => {
  // @ts-ignore
  if (typeof window === 'undefined') {
    return client(url);
  }

  // @ts-ignore
  return null;
};

const prisma = getPrismaClient();
export default prisma;

export * from './types';
export * from '@prisma/client/ecominate';

@arthurfiorette
Copy link
Owner

Hey @jakeleventhal, thanks for almost instantly reporting this bug after prisma 4.16.0 release! It's live at v2.5.0!
Feel free to reopen this PR if needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants