-
-
Notifications
You must be signed in to change notification settings - Fork 207
Add Aggregate Query Support to Parse Flutter SDK #1041
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: master
Are you sure you want to change the base?
Changes from all commits
8ad7e19
e65a3f5
c093ff1
29d83f5
3a4feb6
bd2b057
7dabdcb
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
part of '../../parse_server_sdk.dart'; | ||
|
||
/// A class that allows aggregation queries on a Parse Server class using a pipeline. | ||
/// | ||
/// Example usage: | ||
/// ```dart | ||
/// final aggregate = ParseAggregate('GameScore', pipeline: { | ||
/// '\$group': { | ||
/// '_id': '\$userId', | ||
/// 'totalScore': {'\$sum': '\$score'} | ||
/// } | ||
/// }); | ||
/// final response = await aggregate.execute(); | ||
/// ``` | ||
class ParseAggregate { | ||
/// The name of the Parse class to perform the aggregation on. | ||
final String className; | ||
|
||
/// The aggregation pipeline operations. | ||
/// | ||
/// Each operation should follow MongoDB-like syntax. | ||
/// Example: | ||
/// ```dart | ||
/// { | ||
/// '\$group': { | ||
/// '_id': '\$userId', | ||
/// 'totalScore': {'\$sum': '\$score'} | ||
/// } | ||
/// } | ||
/// ``` | ||
Map<String, dynamic> pipeline; | ||
|
||
/// Whether to enable debug mode for this request. | ||
final bool? debug; | ||
|
||
/// The custom ParseClient to use for the request (optional). | ||
final ParseClient? client; | ||
|
||
/// If true, includes the session ID automatically in the request (optional). | ||
final bool? autoSendSessionId; | ||
|
||
/// Optional override for the Parse class name used in response handling. | ||
final String? parseClassName; | ||
|
||
/// Creates a new [ParseAggregate] instance to perform aggregation queries. | ||
/// | ||
/// [className] is required and specifies the target Parse class. | ||
/// [pipeline] must contain at least one aggregation operation. | ||
ParseAggregate( | ||
this.className, { | ||
required this.pipeline, | ||
this.debug, | ||
this.client, | ||
this.autoSendSessionId, | ||
this.parseClassName, | ||
}); | ||
|
||
/// Executes the aggregation query using the configured pipeline. | ||
/// | ||
/// Returns a [ParseResponse] containing the results of the aggregation. | ||
/// Throws [ArgumentError] if the pipeline is empty. | ||
Future<ParseResponse> execute() async { | ||
Map<String, String> _pipeline = {}; | ||
|
||
if (pipeline.isEmpty) { | ||
throw ArgumentError( | ||
'pipeline must not be empty. Please add pipeline operations to aggregate data. ' | ||
'Example: {"\$group": {"_id": "\$userId", "totalScore": {"\$sum": "\$score"}}}', | ||
); | ||
} else { | ||
_pipeline.addAll({ | ||
'pipeline': jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList()) | ||
}); | ||
} | ||
|
||
final debugBool = isDebugEnabled(objectLevelDebug: debug); | ||
final result = await ParseObject(className)._client.get( | ||
Uri.parse('${ParseCoreData().serverUrl}$keyEndPointAggregate$className').replace( | ||
queryParameters: {'pipeline': jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList())} | ||
).toString(), | ||
); | ||
|
||
|
||
return handleResponse<ParseObject>( | ||
ParseObject(className), | ||
result, | ||
ParseApiRQ.get, | ||
debugBool, | ||
parseClassName ?? 'ParseBase', | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class UrlReplace{ | ||
String? scheme; | ||
String? userInfo; | ||
String? host; | ||
int? port; | ||
String? path; | ||
Iterable<String>? pathSegments; | ||
String? query; | ||
Map<String, dynamic>? queryParameters; | ||
String? fragment; | ||
|
||
UrlReplace({ | ||
this.scheme, | ||
this.userInfo, | ||
this.host, | ||
this.port, | ||
this.path, | ||
this.pathSegments, | ||
this.query, | ||
this.queryParameters, | ||
this.fragment, | ||
}); | ||
|
||
} | ||
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,7 +24,7 @@ dependencies: | |||||||||||
# Networking | ||||||||||||
dio: ^5.7.0 | ||||||||||||
http: ^1.2.0 | ||||||||||||
web_socket_channel: ^2.4.3 | ||||||||||||
web_socket_channel: ^3.0.3 | ||||||||||||
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. 💡 Verification agent 🧩 Analysis chainVerify compatibility with web_socket_channel major version upgrade The 🌐 Web query:
💡 Result: Breaking Changes in
|
Breaking Change | Details |
---|---|
Constructor removal | No direct WebSocketChannel() instantiation; use factory constructors instead |
Abstract interface | WebSocketChannel is now abstract; use specific implementations |
Exception change in ready |
Throws WebSocketChannelException (previously WebSocketException ) |
Default web adapter | Uses package:web_socket adapter for web via WebSocketChannel.connect |
Developers upgrading to v3.0.0 should adjust their code to accommodate these changes[1][6].
Citations:
- 1: https://github.com/dart-lang/web_socket_channel/blob/master/CHANGELOG.md
- 2: https://github.com/dart-lang/web_socket_channel/releases
- 3: https://chromium.googlesource.com/external/github.com/dart-lang/shelf_web_socket/+/24fb8a04befa75a94ac63a27047b231d1a22aab4/CHANGELOG.md
- 4: https://pub.dev/packages/web_socket_channel
- 5: https://dartfrog.vgv.dev/docs/tutorials/web_socket_counter
- 6: https://pub.dev/packages/web_socket_channel/changelog
- 7: https://pub.dev/packages/centrifuge/changelog
- 8: https://pub.dev/packages/deepgram_speech_to_text/changelog
- 9: https://dartfrog.vgv.dev/docs/advanced/web_socket
- 10: https://websockets.readthedocs.io/en/stable/project/changelog.html
Validate Breaking Changes for web_socket_channel v3.0.0
We’ve bumped web_socket_channel
from ^2.4.3
to ^3.0.3
, which includes these breaking changes:
- Removal of the direct
WebSocketChannel()
constructor – you must now useWebSocketChannel.connect(...)
. WebSocketChannel
is now an abstract interface.IOWebSocketChannel.ready
throwsWebSocketChannelException
(instead ofWebSocketException
).- Default web implementation now uses the
package:web_socket
adapter.
Please audit the Dart code for:
- Any instantiation of
WebSocketChannel()
(replace withconnect
). - Direct uses of
IOWebSocketChannel
and calls to itsready
property (update exception handling). - Web‐platform socket code relying on the old adapter.
Make the necessary updates or confirm that your code paths already comply with the new API.
🤖 Prompt for AI Agents (early access)
In packages/dart/pubspec.yaml at line 27, the web_socket_channel dependency has been upgraded from ^2.4.3 to ^3.0.3, which introduces breaking changes. Audit all Dart code that uses web_socket_channel for direct instantiation of WebSocketChannel() and replace these with WebSocketChannel.connect(...) factory methods. Also, update any exception handling around IOWebSocketChannel.ready to catch WebSocketChannelException instead of WebSocketException. Verify web platform socket code to ensure compatibility with the new package:web_socket adapter. Make these code adjustments to align with the new major version API.
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.
Are these dependency upgrades necessary for this feature?
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.
No but your package dependancies are old and I upgrade it to be compatible with new versions
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.
Coyld you please remove any changes that are not necessary for this PR? You could open another, separate PR for the dependency upgrades, that should only contain the upgrades.
Original file line number | Diff line number | Diff line change | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ dependencies: | ||||||||||||||||
flutter: | |||||||||||||||||
sdk: flutter | |||||||||||||||||
|
|||||||||||||||||
parse_server_sdk: ^6.4.0 | |||||||||||||||||
parse_server_sdk: ^8.0.0 | |||||||||||||||||
# Uncomment for local testing | |||||||||||||||||
#parse_server_sdk: | |||||||||||||||||
# path: ../dart | |||||||||||||||||
|
@@ -40,14 +40,14 @@ dependencies: | ||||||||||||||||
|
|||||||||||||||||
# Utils | |||||||||||||||||
path_provider: ^2.1.4 | |||||||||||||||||
package_info_plus: ^5.0.1 | |||||||||||||||||
package_info_plus: ^8.3.0 | |||||||||||||||||
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. 💡 Verification agent 🧩 Analysis chainCheck for potential issues with package_info_plus upgrade The 🌐 Web query:
💡 Result: Breaking Changes Between
|
Version | Breaking Change Description |
---|---|
5.0.1 | versionJsonUrl can omit .json extension on web[3] |
7.0.0 | buildSignature uses SHA-256 on Android[1] |
If you rely on either buildSignature
for Android or serve web builds with a specific versionJsonUrl
file extension, carefully review your implementation when upgrading between these versions.
Further Recommendations:
- Review the full changelog for
package_info_plus
for all detailed updates between your installed version and the latest[1]. - Test each platform you support (Android, iOS, Web) after upgrading to catch any behavioral nuances, especially around version/build info retrieval and signature computation.
Citations:
- 1: https://pub.dev/packages/package_info_plus/changelog
- 2: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/CHANGELOG.md
- 3: https://pub.dev/packages/package_info_plus/versions/5.0.1/changelog
- 4: package_info_plus 5.0.1 not supporting. fluttercommunity/wakelock_plus#16
- 5: https://docs.flutter.dev/release/breaking-changes
- 6: https://www.dhiwise.com/post/complete-guide-to-using-flutter-package-info-plus-for-app
- 7: https://pub.dev/packages/sentry_flutter/versions/8.14.1/changelog
- 8: https://pub.dev/packages/package_info_plus
- 9: [Question]: Error build android since package_info_plus 3.0.1 fluttercommunity/plus_plugins#1290
- 10: https://community.flutterflow.io/ask-the-community/post/execution-failed-for-task-package-info-plus-compilereleasejavawithjavac-lx9rOtUbT6bNb4f
Review Breaking Changes in package_info_plus Upgrade
The jump from ^5.0.1
to ^8.3.0
introduces a couple of breaking changes you should verify:
- Android (v7.0.0):
buildSignature
now uses SHA-256 instead of the previous hashing method. If your app logic depends on this value, update or re-test accordingly. - Web (v5.0.1):
versionJsonUrl
no longer requires a.json
extension. Ensure your server or deployment doesn’t rely on a fixed.json
suffix.
All other core PackageInfo
APIs (version, build number, etc.) remain unchanged. Please review your implementation, adjust any dependent logic, and test each platform (Android, iOS, Web) after upgrading.
🤖 Prompt for AI Agents (early access)
In packages/flutter/pubspec.yaml at line 43, the package_info_plus dependency was upgraded from ^5.0.1 to ^8.3.0, which includes breaking changes. Review your app code for any usage of buildSignature on Android and update or retest it due to the switch to SHA-256 hashing in v7.0.0. Also, verify your web deployment does not rely on a .json extension in versionJsonUrl, adjusting server or deployment settings if necessary. Finally, test all platforms thoroughly to ensure compatibility with the new package version.
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.
💡 Verification agent
🧩 Analysis chain
Updated linting rules
The flutter_lints
dev dependency has been updated from ^4.0.0
to ^5.0.0
. This may introduce new linting rules or deprecate existing ones.
🌐 Web query:
What are the changes in flutter_lints between version 4.0.0 and 5.0.0?
💡 Result:
Changes in flutter_lints
Between Versions 4.0.0 and 5.0.0
Summary Table
Category | 4.0.0 | 5.0.0 |
---|---|---|
package:lints dependency |
4.0.0 | 5.0.0 |
Minimum SDK | Flutter 3.13 / Dart 3.1 | Flutter 3.24 / Dart 3.5 |
Lints Added | library_annotations no_wildcard_variable_uses |
invalid_runtime_check_with_js_interop_types unnecessary_library_name |
Lints Removed | package_prefixed_library_names library_names |
avoid_null_checks_in_equality_operators prefer_const_constructors prefer_const_declarations prefer_const_literals_to_create_immutables |
Detailed Changes
Dependency and SDK Updates
- The internal dependency was updated:
package:lints
upgraded from version 4.0.0 to 5.0.0. - Minimum required Flutter and Dart SDK versions increased to Flutter 3.24 and Dart 3.5[1][2][4].
New Lints Added
invalid_runtime_check_with_js_interop_types
: Prevents incorrect runtime checks with interop types, improving JavaScript interoperability safety.unnecessary_library_name
: Discourages unnecessary library name declarations for cleaner code[1][4].
Lints Removed
avoid_null_checks_in_equality_operators
: This removal gives developers more control over hownull
is handled in equality checks[1][4].prefer_const_constructors
prefer_const_declarations
prefer_const_literals_to_create_immutables
These three "prefer_const_" lints were removed to simplify constant usage recommendations in Flutter projects, as they were sometimes seen as overly restrictive[1][4].
Removed in 4.0.0 (Still Absent in 5.0.0)
package_prefixed_library_names
library_names
These were already removed in the shift from 3.0.2 to 4.0.0[1].
Added in 4.0.0 (Still Present Unless Otherwise Stated)
library_annotations
no_wildcard_variable_uses
What This Means for Your Project
- Upgrading to 5.0.0 may introduce new lint warnings related to JavaScript interop and unnecessary library name usage.
- Code that previously failed the removed lints (
prefer_const_*
andavoid_null_checks_in_equality_operators
) will no longer be flagged. - Projects must now use newer Flutter and Dart SDKs (at least Flutter 3.24 / Dart 3.5)[1][2][4].
Upgrading will keep your project aligned with the latest best practices and Dart ecosystem trends, and may lead to cleaner, more maintainable codebases[4].
Citations:
- 1: https://pub.dev/packages/flutter_lints/changelog
- 2: https://pub.dev/packages/flutter_lints/versions
- 3: https://github.com/FlutterGen/flutter_gen/blob/main/CHANGELOG.md
- 4: https://www.victorcarreras.dev/2024/10/whats-new-in-flutter-lints-500-key.html
- 5: https://docs.flutter.dev/release/breaking-changes/flutter-lints-package
- 6: https://gitlab.com/TheOneWithTheBraid/f_wallet/-/merge_requests/67
- 7: https://github.com/inway/flutter_ringtone_player/blob/main/CHANGELOG.md
- 8: error fluttercommunity/flutter_launcher_icons#606
- 9: https://github.com/flutter-form-builder-ecosystem/form_builder_validators/actions/runs/11050840691
- 10: https://community.flutterflow.io/c/whats-new-in-flutterflow/post/what-s-new-in-flutterflow-october-22-2024-SwPJhrzf93cjCkp
Update Dart/Flutter SDK Constraints & Address New Lint Rules
Please ensure the upgrade to flutter_lints: ^5.0.0
is fully supported:
• In packages/flutter/pubspec.yaml
, bump your environment SDKs to meet the new minimums:
environment:
sdk: ">=3.5.0 <4.0.0"
flutter: ">=3.24.0"
• Run
flutter pub upgrade
flutter analyze
to surface the two new lints:
invalid_runtime_check_with_js_interop_types
unnecessary_library_name
• Review and adjust any code patterns that relied on lints now removed:
avoid_null_checks_in_equality_operators
prefer_const_constructors
prefer_const_declarations
prefer_const_literals_to_create_immutables
🤖 Prompt for AI Agents (early access)
In packages/flutter/pubspec.yaml at line 50, after updating flutter_lints to ^5.0.0, update the environment SDK constraints to sdk: ">=3.5.0 <4.0.0" and flutter: ">=3.24.0" to meet new minimum requirements. Then run flutter pub upgrade and flutter analyze to detect new lint warnings for invalid_runtime_check_with_js_interop_types and unnecessary_library_name. Finally, review and modify code to comply with these new lints and adjust any code relying on removed lints like avoid_null_checks_in_equality_operators and the prefer_const_* rules.
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
Add documentation and consider using Dart's Uri class instead.
This class lacks documentation explaining its purpose and usage. Additionally, it appears to duplicate functionality that's already available in Dart's
Uri
class.class UrlReplace {
Uri
class could be used directly🤖 Prompt for AI Agents (early access)