-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add support for Parse.Query.include
in LiveQuery
#9827
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
base: alpha
Are you sure you want to change the base?
Conversation
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughSupport for the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant LiveQueryServer
participant Database
Client->>LiveQueryServer: Subscribe to class with include (e.g., Queue include user)
LiveQueryServer->>Database: Register subscription
Note over LiveQueryServer: On object creation or update
Database-->>LiveQueryServer: New/updated object (with pointer)
LiveQueryServer->>Database: Fetch related pointer objects (e.g., user)
Database-->>LiveQueryServer: Return full related objects
LiveQueryServer->>Client: Send event with included pointer objects
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm warn EBADENGINE Unsupported engine { Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) |
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: 3
🧹 Nitpick comments (1)
src/LiveQuery/ParseLiveQueryServer.ts (1)
1085-1200
: Consider performance optimizationsThe implementation is well-structured with proper batching and security considerations. However, there are some performance improvements to consider:
- if (obj.className === '_User' && !auth.isMaster) { - delete obj.sessionToken; - delete obj.authData; - } + if (obj.className === '_User' && !auth.isMaster) { + obj.sessionToken = undefined; + obj.authData = undefined; + }This avoids the performance impact of the
delete
operator as suggested by static analysis.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
spec/ParseLiveQuery.spec.js
(1 hunks)src/LiveQuery/ParseLiveQueryServer.ts
(7 hunks)
🧰 Additional context used
🧠 Learnings (2)
spec/ParseLiveQuery.spec.js (4)
Learnt from: RahulLanjewar93
PR: parse-community/parse-server#9744
File: spec/ParseLiveQuery.spec.js:0-0
Timestamp: 2025-04-30T19:31:35.344Z
Learning: In the Parse Server codebase, the functions in QueryTools.js are typically tested through end-to-end behavior tests rather than direct unit tests, even though the functions are exported from the module.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
src/LiveQuery/ParseLiveQueryServer.ts (4)
Learnt from: RahulLanjewar93
PR: parse-community/parse-server#9744
File: spec/ParseLiveQuery.spec.js:0-0
Timestamp: 2025-04-30T19:31:35.344Z
Learning: In the Parse Server codebase, the functions in QueryTools.js are typically tested through end-to-end behavior tests rather than direct unit tests, even though the functions are exported from the module.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
🪛 Biome (1.9.4)
src/LiveQuery/ParseLiveQueryServer.ts
[error] 1185-1185: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1186-1186: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1203-1203: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
[error] 1223-1223: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
🔇 Additional comments (6)
src/LiveQuery/ParseLiveQueryServer.ts (6)
28-29
: LGTM!The imports are appropriate for the include functionality -
RestQuery
for querying related objects andmasterAuth
for elevated permissions when fetching included data.
246-247
: LGTM!Correctly applies includes to the deleted object after converting to JSON and before sending to the client.
399-404
: LGTM!Properly applies includes to both current and original objects in update events, ensuring clients receive complete data for comparison.
956-960
: LGTM!Correctly handles the
include
field from subscription requests, supporting both array and comma-separated string formats, consistent with howkeys
is handled.
1253-1269
: LGTM!Clean implementation that properly handles multiple include paths by wrapping the object for batch processing.
679-695
: Security concern: confirm sensitive _User fields are filtered under masterAuthThe call to
includeObject
usesmasterAuth
, which bypasses ACLs. Please verify that theincludeObject
implementation still sanitizes sensitive_User
fields (e.g., passwords, emailVerified, authData) even when using master privileges. If it doesn’t, add explicit filtering to prevent exposing private user data.• File: src/LiveQuery/ParseLiveQueryServer.ts (lines 679–695)
• Method:_applyInclude
replacePointers(object: any, path: Array<string>, replace: any): any { | ||
if (object instanceof Array) { | ||
return object | ||
.map(obj => this.replacePointers(obj, path, replace)) | ||
.filter(obj => typeof obj !== 'undefined'); | ||
} | ||
if (typeof object !== 'object' || !object) { | ||
return object; | ||
} | ||
if (path.length === 0) { | ||
if (object && object.__type === 'Pointer') { | ||
return replace[object.objectId]; | ||
} | ||
return object; | ||
} | ||
const subObject = object[path[0]]; | ||
if (!subObject) { | ||
return object; | ||
} | ||
const newSub = this.replacePointers(subObject, path.slice(1), replace); | ||
const answer: any = {}; | ||
for (const key in object) { | ||
if (key === path[0]) { | ||
answer[key] = newSub; | ||
} else { | ||
answer[key] = object[key]; | ||
} | ||
} | ||
return answer; | ||
} |
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.
🛠️ Refactor suggestion
Use Array.isArray() for consistency
- if (object instanceof Array) {
+ if (Array.isArray(object)) {
return object
.map(obj => this.replacePointers(obj, path, replace))
.filter(obj => typeof obj !== 'undefined');
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
replacePointers(object: any, path: Array<string>, replace: any): any { | |
if (object instanceof Array) { | |
return object | |
.map(obj => this.replacePointers(obj, path, replace)) | |
.filter(obj => typeof obj !== 'undefined'); | |
} | |
if (typeof object !== 'object' || !object) { | |
return object; | |
} | |
if (path.length === 0) { | |
if (object && object.__type === 'Pointer') { | |
return replace[object.objectId]; | |
} | |
return object; | |
} | |
const subObject = object[path[0]]; | |
if (!subObject) { | |
return object; | |
} | |
const newSub = this.replacePointers(subObject, path.slice(1), replace); | |
const answer: any = {}; | |
for (const key in object) { | |
if (key === path[0]) { | |
answer[key] = newSub; | |
} else { | |
answer[key] = object[key]; | |
} | |
} | |
return answer; | |
} | |
replacePointers(object: any, path: Array<string>, replace: any): any { | |
if (Array.isArray(object)) { | |
return object | |
.map(obj => this.replacePointers(obj, path, replace)) | |
.filter(obj => typeof obj !== 'undefined'); | |
} | |
if (typeof object !== 'object' || !object) { | |
return object; | |
} | |
if (path.length === 0) { | |
if (object && object.__type === 'Pointer') { | |
return replace[object.objectId]; | |
} | |
return object; | |
} | |
const subObject = object[path[0]]; | |
if (!subObject) { | |
return object; | |
} | |
const newSub = this.replacePointers(subObject, path.slice(1), replace); | |
const answer: any = {}; | |
for (const key in object) { | |
if (key === path[0]) { | |
answer[key] = newSub; | |
} else { | |
answer[key] = object[key]; | |
} | |
} | |
return answer; | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 1223-1223: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
🤖 Prompt for AI Agents
In src/LiveQuery/ParseLiveQueryServer.ts between lines 1222 and 1251, replace
the use of 'object instanceof Array' with 'Array.isArray(object)' to check if
the variable is an array. This change improves consistency and reliability in
array type checking. Update the condition accordingly without altering the rest
of the logic.
findPointers(object: any, path: Array<string>): any[] { | ||
if (object instanceof Array) { | ||
return object.map(x => this.findPointers(x, path)).flat(); | ||
} | ||
if (typeof object !== 'object' || !object) { | ||
return []; | ||
} | ||
if (path.length === 0) { | ||
if (object === null || object.__type === 'Pointer') { | ||
return [object]; | ||
} | ||
return []; | ||
} | ||
const subObject = object[path[0]]; | ||
if (!subObject) { | ||
return []; | ||
} | ||
return this.findPointers(subObject, path.slice(1)); | ||
} |
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.
🛠️ Refactor suggestion
Use Array.isArray() for more robust array detection
The recursive implementation is correct, but should use Array.isArray()
for better compatibility:
- if (object instanceof Array) {
+ if (Array.isArray(object)) {
return object.map(x => this.findPointers(x, path)).flat();
}
This handles arrays from different execution contexts correctly, as noted by static analysis.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
findPointers(object: any, path: Array<string>): any[] { | |
if (object instanceof Array) { | |
return object.map(x => this.findPointers(x, path)).flat(); | |
} | |
if (typeof object !== 'object' || !object) { | |
return []; | |
} | |
if (path.length === 0) { | |
if (object === null || object.__type === 'Pointer') { | |
return [object]; | |
} | |
return []; | |
} | |
const subObject = object[path[0]]; | |
if (!subObject) { | |
return []; | |
} | |
return this.findPointers(subObject, path.slice(1)); | |
} | |
findPointers(object: any, path: Array<string>): any[] { | |
if (Array.isArray(object)) { | |
return object.map(x => this.findPointers(x, path)).flat(); | |
} | |
if (typeof object !== 'object' || !object) { | |
return []; | |
} | |
if (path.length === 0) { | |
if (object === null || object.__type === 'Pointer') { | |
return [object]; | |
} | |
return []; | |
} | |
const subObject = object[path[0]]; | |
if (!subObject) { | |
return []; | |
} | |
return this.findPointers(subObject, path.slice(1)); | |
} |
🧰 Tools
🪛 Biome (1.9.4)
[error] 1203-1203: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
🤖 Prompt for AI Agents
In src/LiveQuery/ParseLiveQueryServer.ts around lines 1202 to 1220, replace the
use of 'object instanceof Array' with 'Array.isArray(object)' to detect arrays
more reliably across different execution contexts. This change ensures the
function correctly identifies arrays regardless of their origin, improving
compatibility and correctness of the recursive pointer finding logic.
spec/ParseLiveQuery.spec.js
Outdated
it_id('a1b7fa01-877e-46e2-9601-d312ebb9b33a')(fit)('handles query include', async done => { | ||
await reconfigureServer({ | ||
liveQuery: { | ||
classNames: ['Queue'], | ||
}, | ||
startLiveQueryServer: true, | ||
verbose: false, | ||
silent: true, | ||
}); | ||
|
||
const user = new Parse.User(); | ||
user.setUsername('testuser'); | ||
user.setPassword('password'); | ||
await user.signUp(); | ||
|
||
const query = new Parse.Query('Queue'); | ||
query.include('user'); | ||
const subscription = await query.subscribe(); | ||
subscription.on('create', obj => { | ||
expect(obj.get('user').get('username')).toBe('testuser'); | ||
done(); | ||
}); | ||
|
||
const queue = new Parse.Object('Queue'); | ||
queue.set('user', user); | ||
await queue.save(); | ||
}); |
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.
Change fit()
to it()
before committing
The test correctly validates the include functionality using the recommended async/await pattern. However, fit()
focuses only this test and skips all others.
- it_id('a1b7fa01-877e-46e2-9601-d312ebb9b33a')(fit)('handles query include', async done => {
+ it_id('a1b7fa01-877e-46e2-9601-d312ebb9b33a')(it)('handles query include', async done => {
Consider adding more test cases to cover:
- Multiple includes
- Nested includes
- Include with keys/exclude keys
- Error scenarios
🤖 Prompt for AI Agents
In spec/ParseLiveQuery.spec.js around lines 1312 to 1338, change the test
function from fit() to it() to ensure all tests run instead of focusing only on
this one. Additionally, expand test coverage by adding new test cases that cover
multiple includes, nested includes, include with keys/exclude keys, and error
scenarios to thoroughly validate the include functionality.
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
♻️ Duplicate comments (2)
src/LiveQuery/ParseLiveQueryServer.ts (2)
1205-1223
: Use Array.isArray() for more robust array detection.The recursive implementation is correct, but should use
Array.isArray()
for better compatibility:- if (object instanceof Array) { + if (Array.isArray(object)) { return object.map(x => this.findPointers(x, path)).flat(); }This handles arrays from different execution contexts correctly, as noted by static analysis.
1225-1254
: Use Array.isArray() for consistency.- if (object instanceof Array) { + if (Array.isArray(object)) { return object .map(obj => this.replacePointers(obj, path, replace)) .filter(obj => typeof obj !== 'undefined'); }
🧹 Nitpick comments (1)
src/LiveQuery/ParseLiveQueryServer.ts (1)
1088-1203
: LGTM! Comprehensive include path implementation.The
includePath
method is well-structured with proper batching, filtering, and security considerations for User objects.Consider the static analysis suggestion to use undefined assignment instead of delete for better performance:
if (obj.className === '_User' && !auth.isMaster) { - delete obj.sessionToken; - delete obj.authData; + obj.sessionToken = undefined; + obj.authData = undefined; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
spec/ParseLiveQuery.spec.js
(1 hunks)src/LiveQuery/ParseLiveQueryServer.ts
(7 hunks)src/LiveQuery/RequestSchema.js
(2 hunks)types/LiveQuery/ParseLiveQueryServer.d.ts
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- spec/ParseLiveQuery.spec.js
🧰 Additional context used
🧠 Learnings (2)
types/LiveQuery/ParseLiveQueryServer.d.ts (4)
Learnt from: RahulLanjewar93
PR: parse-community/parse-server#9744
File: spec/ParseLiveQuery.spec.js:0-0
Timestamp: 2025-04-30T19:31:35.344Z
Learning: In the Parse Server codebase, the functions in QueryTools.js are typically tested through end-to-end behavior tests rather than direct unit tests, even though the functions are exported from the module.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
src/LiveQuery/ParseLiveQueryServer.ts (4)
Learnt from: RahulLanjewar93
PR: parse-community/parse-server#9744
File: spec/ParseLiveQuery.spec.js:0-0
Timestamp: 2025-04-30T19:31:35.344Z
Learning: In the Parse Server codebase, the functions in QueryTools.js are typically tested through end-to-end behavior tests rather than direct unit tests, even though the functions are exported from the module.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
🪛 Biome (1.9.4)
src/LiveQuery/ParseLiveQueryServer.ts
[error] 1188-1188: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1189-1189: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1206-1206: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
[error] 1226-1226: Use Array.isArray() instead of instanceof Array.
instanceof Array returns false for array-like objects and arrays from other execution contexts.
Unsafe fix: Use Array.isArray() instead.
(lint/suspicious/useIsArray)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Docker Build
🔇 Additional comments (10)
src/LiveQuery/RequestSchema.js (2)
81-88
: LGTM! Schema definition follows established patterns.The
include
property definition is consistent with existing array properties (keys
andwatch
) and includes appropriate validation constraints.
135-142
: LGTM! Consistent schema definition across operations.The
include
property is correctly duplicated in the update operation schema, maintaining consistency with the subscribe operation.types/LiveQuery/ParseLiveQueryServer.d.ts (1)
28-28
: LGTM! Type declarations properly define include functionality.The new method signatures are well-defined with appropriate parameter types and return types, following the existing conventions in the file.
Also applies to: 40-43
src/LiveQuery/ParseLiveQueryServer.ts (7)
2-28
: LGTM! Import reorganization supports new functionality.The reorganized imports and new additions are necessary for the include feature implementation.
682-698
: LGTM! Well-implemented include application method.The
_applyInclude
method properly handles null checks, extracts include paths from subscription info, and uses master auth for include operations.
245-245
: LGTM! Proper integration of include functionality in delete events.The
_applyInclude
call is correctly placed after object conversion and uses proper await syntax.
396-407
: LGTM! Comprehensive include handling for save events.The implementation correctly applies includes to both current and original objects, with proper null checks and async handling.
959-963
: LGTM! Consistent include parsing in subscription handling.The include parsing follows the established pattern used for keys, properly handling both array and comma-separated string formats.
1256-1272
: LGTM! Clean orchestration method.The
includeObject
method provides a clean interface for processing multiple include paths sequentially.
561-561
: LGTM! Minor formatting improvement.The return type annotation formatting is improved for better readability.
Parse.Query.include
in LiveQuery
Pull Request
Issue
Closes: #1686
Approach
Add Parse.Query.include to LiveQuery.
Tasks
include
onsubscribe
andresubscribe
--> feat: Add support forParse.Query.include
in LiveQuery Parse-SDK-JS#2694Summary by CodeRabbit
New Features
Tests