prisma: Prisma Client Extension Error After Updating to 4.16.1

Bug description

I’m getting this issue with Prisma Client Extensions after upgrading to 4.16.1. This doesn’t happen at all on 14.15.0. I’d love to know what’s going on:

src/modules/common/prisma/prismaExtensions/useSupabaseRowLevelSecurity.ts:81:10 - error TS2615: Type of property 'AND' circularly references itself in mapped type '{ [K in keyof { AND?: Enumerable<current_locationScalarWhereWithAggregatesInput>; OR?: Enumerable<current_locationScalarWhereWithAggregatesInput>; ... 6 more ...; lat?: string | ... 3 more ... | DecimalWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingFields<...> : never : {} exte...'.

 81   return Prisma.defineExtension((client: BasePrismaClient) =>
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 82     client.$extends({
    ~~~~~~~~~~~~~~~~~~~~~
... 
104     }),
    ~~~~~~~
105   );
    ~~~

src/modules/common/prisma/prismaExtensions/useSupabaseRowLevelSecurity.ts:81:10 - error TS2615: Type of property 'AND' circularly references itself in mapped type '{ [K in keyof { AND?: Enumerable<eventsScalarWhereWithAggregatesInput>; OR?: Enumerable<eventsScalarWhereWithAggregatesInput>; ... 8 more ...; description?: string | StringNullableWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingFields<...> : never : {} extends FieldPaths<...> ? ...'.

 81   return Prisma.defineExtension((client: BasePrismaClient) =>
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 82     client.$extends({
    ~~~~~~~~~~~~~~~~~~~~~
... 
104     }),
    ~~~~~~~
105   );
    ~~~

src/modules/common/prisma/prismaExtensions/useSupabaseRowLevelSecurity.ts:81:10 - error TS2615: Type of property 'AND' circularly references itself in mapped type '{ [K in keyof { AND?: Enumerable<fcm_tokensScalarWhereWithAggregatesInput>; OR?: Enumerable<fcm_tokensScalarWhereWithAggregatesInput>; ... 5 more ...; platform?: string | StringNullableWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingFields<...> : never : {} extends FieldPaths<.....'.

 81   return Prisma.defineExtension((client: BasePrismaClient) =>
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 82     client.$extends({
    ~~~~~~~~~~~~~~~~~~~~~
... 
104     }),
    ~~~~~~~
105   );
    ~~~

How to reproduce

This is the extension I created and this is what I have:

// prisma-extension-enable-supabase-row-level-security

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

export interface SupabaseRowLevelSecurityOptions {
  /**
   * The client extension name
   * @default 'supabaseRowLevelSecurity'
   */
  name?: string;
  /**
   * The name of the Postgres setting to use for the claims, `request.jwt.claims` by default.
   * Supabase sets using set_config() and get with current_setting()
   *
   * @default 'request.jwt.claims'
   */
  claimsSetting?: string;
  /**
   * A function that returns the JWT claims to use for the current request decoded from the Supabase access token.
   *
   * E.g.:
   *
   * {
   *   "aud": "authenticated",
   *   "exp": 1675711033,
   *   "sub": "00000000-0000-0000-0000-000000000000",
   *   "email": "user@example.com",
   *   "phone": "",
   *   "app_metadata": {
   *     "provider": "email",
   *     "providers": [
   *       "email"
   *     ]
   *   },
   *   "user_metadata": {},
   *   "role": "authenticated",
   *   "aal": "aal1",
   *   "amr": [
   *     {
   *       "method": "otp",
   *       "timestamp": 1675696651
   *     }
   *   ],
   *   "session_id": "000000000000-0000-0000-0000-000000000000"
   *  }
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  claimsFn?: undefined | (() => Record<string, any>);
  /**
   * The error to throw when the policy check fails.
   */
  policyError?: Error;
  /**
   * Log errors to the console.
   * @default false
   */
  logging?: boolean;
}

const defaultSupabaseRowLevelSecurityOptions: SupabaseRowLevelSecurityOptions =
  {
    name: 'useSupabaseRowLevelSecurity',
    claimsSetting: 'request.jwt.claims',
    claimsFn: undefined,
    policyError: new Error('Not authorized.'),
    logging: true,
  };

export const useSupabaseRowLevelSecurity = (
  options: SupabaseRowLevelSecurityOptions = defaultSupabaseRowLevelSecurityOptions,
) => {
  const name = options.name || defaultSupabaseRowLevelSecurityOptions.name;
  const claimsFn =
    options.claimsFn || defaultSupabaseRowLevelSecurityOptions.claimsFn;
  const claimsSetting =
    options.claimsSetting ||
    defaultSupabaseRowLevelSecurityOptions.claimsSetting;
  const policyError =
    options.policyError || defaultSupabaseRowLevelSecurityOptions.policyError;

  return Prisma.defineExtension((client: BasePrismaClient) =>
    client.$extends({
      name: name || 'useSupabaseRowLevelSecurity',
      query: {
        $allModels: {
          async $allOperations({ args, query }) {
            const claims = claimsFn ? JSON.stringify(claimsFn() || {}) : '';
            try {
              const [, result] = await client.$transaction([
                client.$executeRaw`SELECT set_config(${claimsSetting}, ${claims}, TRUE)`,
                query(args),
              ]);

              return result;
            } catch (e) {
              if (options.logging) {
                console.error(e);
              }
              throw policyError || e;
            }
          },
        },
      },
    }),
  );
};

Expected behavior

This shouldn’t cause any error.

Prisma information

Information added above.

Environment & setup

N/A

Prisma Version

Environment variables loaded from .env
prisma                  : 4.15.0
@prisma/client          : 4.15.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 8fbc245156db7124f997f4cecdd8d1219e360944 (at ../../../../.nvm/versions/node/v18.15.0/lib/node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 8fbc245156db7124f997f4cecdd8d1219e360944 (at ../../../../.nvm/versions/node/v18.15.0/lib/node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944
Default Engines Hash    : 8fbc245156db7124f997f4cecdd8d1219e360944
Studio                  : 0.484.0
Preview Features        : multiSchema, postgresqlExtensions, clientExtensions

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Hey @moinulmoin @nocturnalflame, could you please give 5.1.0 a try? If the problem still persists, could you please give us a reproduction?

Hey, I am using 5.0.0 now. And it’s working fine.

@janpio I’m trying it right now. Will report in the next 30 minutes!

@janpio My bad. I pasted the wrong prisma version (because I downgraded). However, I can confirm that in version 4.16.1, it does have an error versus in 4.15.0.