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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/runtime/package.jsonis excluded by!**/*.jsonpnpm-lock.yamlis 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
clonealigns with the rest of the export statements.packages/runtime/src/cross/clone.ts (1)
1-25: LGTM!The
clonefunction 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
clonefromcross.
54-54: LGTM!The
preprocessWritePayloadmethod correctly replacesdeepcopywithclone.packages/runtime/src/cross/mutator.ts (2)
12-12: ImportingclonefunctionThe
clonefunction has been imported from./clone. Ensure that this function is properly tested and handles all edge cases.
203-203: UsingclonefunctionThe
clonefunction 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: ImportingclonefunctionThe
clonefunction has been imported from../cross. Ensure that this function is properly tested and handles all edge cases.
152-152: UsingsafeCloneincomposeCompoundUniqueFieldThe
safeClonemethod is used to clonefieldData. This ensures that the original data is not mutated during the composition of compound unique fields.
210-216: AddingsafeClonemethodThe
safeClonemethod 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: ImportingclonefunctionThe
clonefunction has been imported from../cross. Ensure that this function is properly tested and handles all edge cases.
77-77: UsingclonefunctionThe
clonefunction is used to cloneargsif 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: ImportingclonefunctionThe
clonefunction has been imported from../cross. Ensure that this function is properly tested and handles all edge cases.
75-75: Usingclonefunction indoFindmethodThe
clonefunction is used to cloneargsif they are provided. This ensures that the original arguments are not mutated during the processing of the find operation.
145-145: Usingclonefunction inbuildWhereHierarchymethodThe
clonefunction is used to clonewhereconditions. This ensures that the original conditions are not mutated during the hierarchy building process.
220-220: Usingclonefunction inbuildSelectIncludeHierarchymethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the hierarchy building process.
411-411: Usingclonefunction indoCreatemethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the create operation.
627-627: Usingclonefunction inupsertmethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the upsert operation.
645-645: Usingclonefunction indoUpdatemethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the update operation.
665-665: Usingclonefunction indoUpdateManymethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the updateMany operation.
675-675: Usingclonefunction indoUpdateManymethod (findArgs)The
clonefunction is used to cloneargs.where. This ensures that the original conditions are not mutated during the find operation.
686-686: Usingclonefunction indoUpdateManymethod (updatePayload)The
clonefunction is used to cloneargs.data. This ensures that the original data is not mutated during the update operation.
852-852: Usingclonefunction indeletemethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the delete operation.
868-868: Usingclonefunction indoDeleteManymethodThe
clonefunction is used to clonewhereconditions. This ensures that the original conditions are not mutated during the deleteMany operation.
921-921: Usingclonefunction inaggregatemethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the aggregate operation.
949-949: Usingclonefunction incountmethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the count operation.
989-989: Usingclonefunction ingroupBymethodThe
clonefunction is used to cloneargs. This ensures that the original arguments are not mutated during the groupBy operation.
1030-1030: Usingclonefunction inextractSelectIncludemethodThe
clonefunction 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 forcloneis correct.
553-553: LGTM! The use ofcloneto create a deep copy of thepayloadobject is appropriate.
809-809: LGTM! The use ofsafeClonefor cloninguniqueFilteris appropriate.
1004-1004: LGTM! The use ofsafeClonefor cloninguniqueFilteris appropriate.
1036-1036: LGTM! The use ofsafeClonefor cloningselectIncludeCleanis 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
findWithFluentmethod now usessafeCloneto ensure safe cloning of arguments.
141-141: LGTM!The
doFindmethod now usessafeCloneto ensure safe cloning of arguments.
179-179: LGTM!The
createmethod now usessafeCloneto ensure safe cloning of arguments.
446-446: LGTM!The
createManymethod now usessafeCloneto ensure safe cloning of arguments.
483-483: LGTM!The
createManyAndReturnmethod now usessafeCloneto ensure safe cloning of arguments.
689-689: LGTM!The
updatemethod now usessafeCloneto ensure safe cloning of arguments.
1152-1152: LGTM!The
calculatePostUpdateIdsmethod now usessafeCloneto ensure safe cloning of current IDs.
1242-1242: LGTM!The
updateManymethod now usessafeCloneto ensure safe cloning of arguments.
1352-1352: LGTM!The
upsertmethod now usessafeCloneto ensure safe cloning of arguments.
1445-1445: LGTM!The
deleteManymethod now usessafeCloneto ensure safe cloning of arguments.
Fixes #1533