diff --git a/packages/runtime/src/enhancements/create-enhancement.ts b/packages/runtime/src/enhancements/create-enhancement.ts index a8a0b441c..2616ae4b4 100644 --- a/packages/runtime/src/enhancements/create-enhancement.ts +++ b/packages/runtime/src/enhancements/create-enhancement.ts @@ -98,10 +98,6 @@ export type EnhancementContext = { user?: User; }; -let hasPassword: boolean | undefined = undefined; -let hasOmit: boolean | undefined = undefined; -let hasDefaultAuth: boolean | undefined = undefined; - /** * Gets a Prisma client enhanced with all enhancement behaviors, including access * policy, field validation, field omission and password hashing. @@ -129,23 +125,15 @@ export function createEnhancement( ); } - let result = prisma; - - if ( - process.env.ZENSTACK_TEST === '1' || // avoid caching in tests - hasPassword === undefined || - hasOmit === undefined || - hasDefaultAuth === undefined - ) { - const allFields = Object.values(options.modelMeta.models).flatMap((modelInfo) => - Object.values(modelInfo.fields) - ); - hasPassword = allFields.some((field) => field.attributes?.some((attr) => attr.name === '@password')); - hasOmit = allFields.some((field) => field.attributes?.some((attr) => attr.name === '@omit')); - hasDefaultAuth = allFields.some((field) => field.defaultValueProvider); - } + // TODO: move the detection logic into each enhancement + // TODO: how to properly cache the detection result? + const allFields = Object.values(options.modelMeta.models).flatMap((modelInfo) => Object.values(modelInfo.fields)); + const hasPassword = allFields.some((field) => field.attributes?.some((attr) => attr.name === '@password')); + const hasOmit = allFields.some((field) => field.attributes?.some((attr) => attr.name === '@omit')); + const hasDefaultAuth = allFields.some((field) => field.defaultValueProvider); const kinds = options.kinds ?? ALL_ENHANCEMENTS; + let result = prisma; // delegate proxy needs to be wrapped inside policy proxy, since it may translate `deleteMany` // and `updateMany` to plain `delete` and `update` diff --git a/packages/runtime/src/enhancements/utils.ts b/packages/runtime/src/enhancements/utils.ts index 9bc7ce0bc..0e82e65be 100644 --- a/packages/runtime/src/enhancements/utils.ts +++ b/packages/runtime/src/enhancements/utils.ts @@ -1,4 +1,3 @@ -import * as util from 'util'; import { FieldInfo, ModelMeta, resolveField } from '..'; import type { DbClientContract } from '../types'; @@ -6,7 +5,7 @@ import type { DbClientContract } from '../types'; * Formats an object for pretty printing. */ export function formatObject(value: unknown) { - return util.formatWithOptions({ depth: 20 }, value); + return JSON.stringify(value, undefined, 2); } // eslint-disable-next-line @typescript-eslint/no-explicit-any