Skip to content

Commit 184aa74

Browse files
committed
chore(runtime): use custom traverse
1 parent 5a973a4 commit 184aa74

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

packages/runtime/src/enhancements/node/delegate.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import deepmerge, { type ArrayMergeOptions } from 'deepmerge';
3-
import traverse from 'traverse';
43
import { DELEGATE_AUX_RELATION_PREFIX } from '../../constants';
54
import {
65
FieldInfo,
@@ -14,7 +13,7 @@ import {
1413
isDelegateModel,
1514
resolveField,
1615
} from '../../cross';
17-
import { isPlainObject, lowerCaseFirst } from '../../local-helpers';
16+
import { isPlainObject, simpleTraverse, lowerCaseFirst } from '../../local-helpers';
1817
import type { CrudContract, DbClientContract, EnhancementContext } from '../../types';
1918
import type { InternalEnhancementOptions } from './create-enhancement';
2019
import { Logger } from './logger';
@@ -487,12 +486,12 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
487486

488487
const prisma = this.prisma;
489488
const prismaModule = this.options.prismaModule;
490-
traverse(data).forEach(function () {
491-
if (this.key?.startsWith(DELEGATE_AUX_RELATION_PREFIX)) {
489+
simpleTraverse(data, ({ key }) => {
490+
if (key.startsWith(DELEGATE_AUX_RELATION_PREFIX)) {
492491
throw prismaClientValidationError(
493492
prisma,
494493
prismaModule,
495-
`Auxiliary relation field "${this.key}" cannot be set directly`
494+
`Auxiliary relation field "${key}" cannot be set directly`
496495
);
497496
}
498497
});

packages/runtime/src/enhancements/node/policy/policy-utils.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

33
import deepmerge from 'deepmerge';
4-
import traverse from 'traverse';
54
import { z, type ZodError, type ZodObject, type ZodSchema } from 'zod';
65
import { fromZodError } from 'zod-validation-error';
76
import { CrudFailureReason, PrismaErrorCode } from '../../../constants';
@@ -15,7 +14,7 @@ import {
1514
type FieldInfo,
1615
type ModelMeta,
1716
} from '../../../cross';
18-
import { isPlainObject, lowerCaseFirst, upperCaseFirst } from '../../../local-helpers';
17+
import { isPlainObject, simpleTraverse, lowerCaseFirst, upperCaseFirst } from '../../../local-helpers';
1918
import {
2019
AuthUser,
2120
CrudContract,
@@ -691,27 +690,24 @@ export class PolicyUtil extends QueryUtils {
691690
// here we prefix the constraint variables coming from delegated checkers
692691
// with the relation field name to avoid conflicts
693692
const prefixConstraintVariables = (constraint: unknown, prefix: string) => {
694-
return traverse(constraint).map(function (value) {
693+
return simpleTraverse(constraint, ({ value, update }) => {
695694
if (isVariableConstraint(value)) {
696-
this.update(
695+
update(
697696
{
698697
...value,
699698
name: `${prefix}${value.name}`,
700-
},
701-
true
699+
}
702700
);
703701
}
704702
});
705703
};
706704

707-
// eslint-disable-next-line @typescript-eslint/no-this-alias
708-
const that = this;
709-
result = traverse(result).forEach(function (value) {
705+
result = simpleTraverse(result, ({ value, update }) => {
710706
if (isDelegateConstraint(value)) {
711707
const { model: delegateModel, relation, operation: delegateOp } = value;
712-
let newValue = that.getCheckerConstraint(delegateModel, delegateOp ?? operation);
708+
let newValue = this.getCheckerConstraint(delegateModel, delegateOp ?? operation);
713709
newValue = prefixConstraintVariables(newValue, `${relation}.`);
714-
this.update(newValue, true);
710+
update(newValue);
715711
}
716712
});
717713

0 commit comments

Comments
 (0)