-
-
Notifications
You must be signed in to change notification settings - Fork 599
feature: add subscription.find #2735
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -92,18 +92,21 @@ class LiveQuerySubscription { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
subscribePromise: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
unsubscribePromise: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
subscribed: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
client: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
emitter: EventEmitter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
on: EventEmitter['on']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
emit: EventEmitter['emit']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {string | number} id - subscription id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {string} query - query to subscribe to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {string} sessionToken - optional session token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {object} client - LiveQueryClient instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
constructor(id: string | number, query: ParseQuery, sessionToken?: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
constructor(id: string | number, query: ParseQuery, sessionToken?: string, client?: any) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.id = id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.query = query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.sessionToken = sessionToken; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.client = client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.subscribePromise = resolvingPromise(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.unsubscribePromise = resolvingPromise(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.subscribed = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -130,6 +133,21 @@ class LiveQuerySubscription { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
return liveQueryClient.unsubscribe(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Execute a query on this subscription. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
* The results will be delivered via the 'result' event. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
find() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (this.client) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.client.connectPromise.then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.client.socket.send(JSON.stringify({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
op: 'query', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
requestId: this.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+141
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and consider user feedback for missing client. The
Consider these improvements: find() {
if (this.client) {
this.client.connectPromise.then(() => {
- this.client.socket.send(JSON.stringify({
- op: 'query',
- requestId: this.id,
- }));
+ if (this.client.socket) {
+ this.client.socket.send(JSON.stringify({
+ op: 'query',
+ requestId: this.id,
+ }));
+ }
+ }).catch(error => {
+ this.emit('error', error);
});
+ } else {
+ this.emit('error', new Error('Cannot execute find: client not available'));
}
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default LiveQuerySubscription; |
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.
Add null safety check for
data.results
.The RESULT handler assumes
data.results
is always an array. If the server sends a malformed message without theresults
field,data.results.map()
will throw a runtime error.Consider adding a defensive check:
📝 Committable suggestion
🤖 Prompt for AI Agents