Skip to content

Commit

Permalink
use safe-json-stringify to format
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Apr 5, 2024
1 parent e3cb83e commit 231e950
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/runtime/src/enhancements/policy/policy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export class PolicyUtil extends QueryUtils {
throw this.deniedByPolicy(
model,
operation,
`entity ${JSON.stringify(uniqueFilter)} failed policy check`,
`entity ${formatObject(uniqueFilter, false)} failed policy check`,
CrudFailureReason.ACCESS_POLICY_VIOLATION
);
}
Expand All @@ -664,7 +664,7 @@ export class PolicyUtil extends QueryUtils {
throw this.deniedByPolicy(
model,
'update',
`entity ${JSON.stringify(uniqueFilter)} failed update policy check for field "${
`entity ${formatObject(uniqueFilter, false)} failed update policy check for field "${
fieldUpdateGuard.rejectedByField
}"`,
CrudFailureReason.ACCESS_POLICY_VIOLATION
Expand Down Expand Up @@ -712,7 +712,7 @@ export class PolicyUtil extends QueryUtils {
throw this.deniedByPolicy(
model,
operation,
`entity ${JSON.stringify(uniqueFilter)} failed policy check`,
`entity ${formatObject(uniqueFilter, false)} failed policy check`,
CrudFailureReason.ACCESS_POLICY_VIOLATION
);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime/src/enhancements/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import safeJsonStringify from 'safe-json-stringify';
import { FieldInfo, ModelMeta, resolveField } from '..';
import type { DbClientContract } from '../types';

/**
* Formats an object for pretty printing.
*/
export function formatObject(value: unknown) {
return JSON.stringify(value, undefined, 2);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function formatObject(value: any, multiLine = true) {
return multiLine ? safeJsonStringify(value, undefined, 2) : safeJsonStringify(value);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 231e950

Please sign in to comment.