-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(runtime): avoid duplicating non-plain objects #1545
Conversation
WalkthroughWalkthroughThe code changes introduce a new Changes
Assessment against linked issues
Tip Early access features: enabledWe are currently testing the following features in early access:
Note:
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/runtime/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
,!**/*.yaml
Files selected for processing (11)
- packages/runtime/src/cross/clone.ts (1 hunks)
- packages/runtime/src/cross/index.ts (1 hunks)
- packages/runtime/src/cross/mutator.ts (3 hunks)
- packages/runtime/src/enhancements/default-auth.ts (2 hunks)
- packages/runtime/src/enhancements/delegate.ts (17 hunks)
- packages/runtime/src/enhancements/policy/handler.ts (15 hunks)
- packages/runtime/src/enhancements/policy/policy-utils.ts (7 hunks)
- packages/runtime/src/enhancements/proxy.ts (2 hunks)
- packages/runtime/src/enhancements/query-utils.ts (3 hunks)
- packages/runtime/src/enhancements/utils.ts (2 hunks)
- tests/regression/tests/issue-1533.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/runtime/src/enhancements/utils.ts
Additional context used
Biome
packages/runtime/src/cross/mutator.ts
[error] 148-148: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
packages/runtime/src/enhancements/query-utils.ts
[error] 54-57: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 157-157: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
packages/runtime/src/enhancements/proxy.ts
[error] 219-221: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 232-234: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 273-273: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
packages/runtime/src/enhancements/delegate.ts
[error] 92-94: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 132-135: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 170-173: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 286-292: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 307-307: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 330-330: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 455-455: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 672-703: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 736-736: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 799-799: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 807-807: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 979-979: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
packages/runtime/src/enhancements/policy/policy-utils.ts
[error] 65-69: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 67-69: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 79-83: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 81-83: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 92-96: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 94-96: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 105-110: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 116-118: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 378-380: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 416-426: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 523-523: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 867-869: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1108-1108: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1248-1250: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
packages/runtime/src/enhancements/policy/handler.ts
[error] 216-225: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 230-232: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 389-391: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 426-428: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 455-463: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 517-519: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 540-545: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 704-706: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 915-919: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 989-989: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1009-1009: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1043-1054: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1066-1081: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1130-1130: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1222-1224: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1373-1378: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1383-1385: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1434-1436: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1481-1487: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 1205-1205: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
Additional comments not posted (44)
packages/runtime/src/cross/index.ts (1)
1-1
: LGTM!The new export for
clone
aligns with the rest of the export statements.packages/runtime/src/cross/clone.ts (1)
1-25
: LGTM!The
clone
function correctly handles deep cloning of arrays and plain objects, returning other values as-is.tests/regression/tests/issue-1533.test.ts (1)
1-66
: LGTM!The regression test for issue 1533 is well-implemented and covers the described scenarios. The test setup and teardown are handled properly.
packages/runtime/src/enhancements/default-auth.ts (2)
5-5
: LGTM!The import statement has been updated correctly to use
clone
fromcross
.
54-54
: LGTM!The
preprocessWritePayload
method correctly replacesdeepcopy
withclone
.packages/runtime/src/cross/mutator.ts (2)
12-12
: Importingclone
functionThe
clone
function has been imported from./clone
. Ensure that this function is properly tested and handles all edge cases.
203-203
: Usingclone
functionThe
clone
function is used to ensure new object identity. This is a good practice to avoid unintended mutations.packages/runtime/src/enhancements/query-utils.ts (3)
10-10
: Importingclone
functionThe
clone
function has been imported from../cross
. Ensure that this function is properly tested and handles all edge cases.
152-152
: UsingsafeClone
incomposeCompoundUniqueField
The
safeClone
method is used to clonefieldData
. This ensures that the original data is not mutated during the composition of compound unique fields.
210-216
: AddingsafeClone
methodThe
safeClone
method clones an object and ensures it's not empty. This is a good utility function to prevent errors due to empty objects.packages/runtime/src/enhancements/proxy.ts (2)
5-5
: Importingclone
functionThe
clone
function has been imported from../cross
. Ensure that this function is properly tested and handles all edge cases.
77-77
: Usingclone
functionThe
clone
function is used to cloneargs
if they are provided. This ensures that the original arguments are not mutated during the processing of the fluent call.packages/runtime/src/enhancements/delegate.ts (16)
16-16
: Importingclone
functionThe
clone
function has been imported from../cross
. Ensure that this function is properly tested and handles all edge cases.
75-75
: Usingclone
function indoFind
methodThe
clone
function is used to cloneargs
if they are provided. This ensures that the original arguments are not mutated during the processing of the find operation.
145-145
: Usingclone
function inbuildWhereHierarchy
methodThe
clone
function is used to clonewhere
conditions. This ensures that the original conditions are not mutated during the hierarchy building process.
220-220
: Usingclone
function inbuildSelectIncludeHierarchy
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the hierarchy building process.
411-411
: Usingclone
function indoCreate
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the create operation.
627-627
: Usingclone
function inupsert
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the upsert operation.
645-645
: Usingclone
function indoUpdate
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the update operation.
665-665
: Usingclone
function indoUpdateMany
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the updateMany operation.
675-675
: Usingclone
function indoUpdateMany
method (findArgs)The
clone
function is used to cloneargs.where
. This ensures that the original conditions are not mutated during the find operation.
686-686
: Usingclone
function indoUpdateMany
method (updatePayload)The
clone
function is used to cloneargs.data
. This ensures that the original data is not mutated during the update operation.
852-852
: Usingclone
function indelete
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the delete operation.
868-868
: Usingclone
function indoDeleteMany
methodThe
clone
function is used to clonewhere
conditions. This ensures that the original conditions are not mutated during the deleteMany operation.
921-921
: Usingclone
function inaggregate
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the aggregate operation.
949-949
: Usingclone
function incount
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the count operation.
989-989
: Usingclone
function ingroupBy
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the groupBy operation.
1030-1030
: Usingclone
function inextractSelectInclude
methodThe
clone
function is used to cloneargs
. This ensures that the original arguments are not mutated during the extraction of select/include options.packages/runtime/src/enhancements/policy/policy-utils.ts (5)
10-10
: LGTM! The import statement forclone
is correct.
553-553
: LGTM! The use ofclone
to create a deep copy of thepayload
object is appropriate.
809-809
: LGTM! The use ofsafeClone
for cloninguniqueFilter
is appropriate.
1004-1004
: LGTM! The use ofsafeClone
for cloninguniqueFilter
is appropriate.
1036-1036
: LGTM! The use ofsafeClone
for cloningselectIncludeClean
is appropriate.packages/runtime/src/enhancements/policy/handler.ts (11)
28-28
: LGTM!The import statement change is consistent with the summary.
130-130
: LGTM!The
findWithFluent
method now usessafeClone
to ensure safe cloning of arguments.
141-141
: LGTM!The
doFind
method now usessafeClone
to ensure safe cloning of arguments.
179-179
: LGTM!The
create
method now usessafeClone
to ensure safe cloning of arguments.
446-446
: LGTM!The
createMany
method now usessafeClone
to ensure safe cloning of arguments.
483-483
: LGTM!The
createManyAndReturn
method now usessafeClone
to ensure safe cloning of arguments.
689-689
: LGTM!The
update
method now usessafeClone
to ensure safe cloning of arguments.
1152-1152
: LGTM!The
calculatePostUpdateIds
method now usessafeClone
to ensure safe cloning of current IDs.
1242-1242
: LGTM!The
updateMany
method now usessafeClone
to ensure safe cloning of arguments.
1352-1352
: LGTM!The
upsert
method now usessafeClone
to ensure safe cloning of arguments.
1445-1445
: LGTM!The
deleteMany
method now usessafeClone
to ensure safe cloning of arguments.
Fixes #1533