Skip to content

Commit

Permalink
fix: remove runtime dependency to node:utils and node:process
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Apr 5, 2024
1 parent 0aba697 commit 046a57d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
26 changes: 7 additions & 19 deletions packages/runtime/src/enhancements/create-enhancement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ export type EnhancementContext<User extends AuthUser = AuthUser> = {
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.
Expand Down Expand Up @@ -129,23 +125,15 @@ export function createEnhancement<DbClient extends object>(
);
}

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`
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime/src/enhancements/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as util from 'util';
import { FieldInfo, ModelMeta, resolveField } from '..';
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
Expand Down

0 comments on commit 046a57d

Please sign in to comment.