Skip to content

fix: Setting atomic operation on Parse Object returns operation instead of prospective value #860

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

Merged
merged 74 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
39a6068
feat: create ParseOperation class
Nidal-Bakir Mar 19, 2023
f890f2f
Merge branch 'master' into fix_parse_op
Nidal-Bakir Mar 21, 2023
736b29a
create the base class for parse operation
Nidal-Bakir Mar 21, 2023
bc15757
remove the old parse operaion file
Nidal-Bakir Mar 21, 2023
503e4d4
create ParseArray class
Nidal-Bakir Mar 21, 2023
d8c3c41
create Valuable interface and custom exception for parse operations
Nidal-Bakir Mar 21, 2023
47b4970
create add operation class
Nidal-Bakir Mar 21, 2023
35d9661
create AddUnique operation class
Nidal-Bakir Mar 21, 2023
1b70548
create Remove operation class
Nidal-Bakir Mar 21, 2023
1007b03
create increment/decrement operation class
Nidal-Bakir Mar 21, 2023
e2c6838
create add/remove relation operation class
Nidal-Bakir Mar 21, 2023
a45c463
create add/remove relation operation class
Nidal-Bakir Mar 21, 2023
7940c21
update the source file to include the added files to the SDK
Nidal-Bakir Mar 21, 2023
9783535
fix the increment operation
Nidal-Bakir Mar 21, 2023
65033f9
fix the type cast in add relation operation
Nidal-Bakir Mar 21, 2023
37d460a
rename the 'fromJson' function in parse array operation to 'fromFullJ…
Nidal-Bakir Mar 21, 2023
6214c12
fix AddUnique operation not result the expected values when adding fo…
Nidal-Bakir Mar 22, 2023
eecf93d
fix _ParseArray is not a subtype of List
Nidal-Bakir Mar 22, 2023
f358273
introduce parse save state aware child mixin
Nidal-Bakir Mar 23, 2023
9732977
account for operation while saving objects
Nidal-Bakir Mar 24, 2023
0a07fe8
Merge branch 'master' into fix_parse_op
Nidal-Bakir Mar 24, 2023
d21bf90
remove unnecessary check and fromJson in testUnmergeableOperationShou…
Nidal-Bakir Mar 24, 2023
8f5d4a9
fix: decoding from json in parse Array. unexpected requests when remo…
Nidal-Bakir Mar 24, 2023
b2aedd6
fix: parse_add_unique_operation not removing duplicate saved ParseObj…
Nidal-Bakir Mar 24, 2023
71d70cc
introduce ParseRelation as dataType Like parseArray
Nidal-Bakir Mar 27, 2023
ed3601a
remove ParseMergeTool
Nidal-Bakir Mar 27, 2023
45c7253
Merge branch 'master' into fix_parse_op
Nidal-Bakir Mar 27, 2023
70f6341
remove parse_merge.dart file import from parse_server_sdk source file
Nidal-Bakir Mar 27, 2023
307cedb
add onClearUnsaved function to _ParseSaveStateAwareChild interface an…
Nidal-Bakir Mar 28, 2023
cf0b0ce
implement add and remove relation operation
Nidal-Bakir Mar 28, 2023
f53b0e7
fix maybeMergeWithPrevious not accounting for previous _ParseRelation…
Nidal-Bakir Mar 28, 2023
9c977ec
Unskip the skipped tests in relation tests
Nidal-Bakir Mar 28, 2023
32812d5
fix the core files to account for the new ParseOperation, ParseArray,…
Nidal-Bakir Mar 28, 2023
ee3de9f
fix parse_encoder_test
Nidal-Bakir Mar 28, 2023
7bb3f9a
fix: allow the array operations to be incremental in set mode
Nidal-Bakir Apr 5, 2023
3d86d3c
style: rename forSet property to setMode
Nidal-Bakir Apr 5, 2023
0150d3d
feat: create ParseNumber datatype to account for setMode and parallel…
Nidal-Bakir Apr 5, 2023
989c7d2
feat: add onErrorSaving callback to parseSaveStateAwareChild interface
Nidal-Bakir Apr 6, 2023
2b3a6e0
docs: add docs for ParseSaveStateAwareChild
Nidal-Bakir Apr 7, 2023
7397d41
test: add test for setRedirectClassNameForKey query
Nidal-Bakir Apr 7, 2023
a043718
feat: convert the return type from object? to generic T in _Valuable …
Nidal-Bakir Apr 7, 2023
22679f9
test: add tests for ParseArray
Nidal-Bakir Apr 8, 2023
81cd8c6
test: add tests for ParseNumber
Nidal-Bakir Apr 8, 2023
d1fac20
fix: getRelation not storing the relation in the parent object
Nidal-Bakir Apr 9, 2023
823899a
refactor: create function handler for each operation
Nidal-Bakir Apr 9, 2023
08e0dad
refactor: create function handler for operations
Nidal-Bakir Apr 9, 2023
9a09119
test: use setUpAll function to init the parseSDK once per test file r…
Nidal-Bakir Apr 9, 2023
268687f
fix: ParseRelation getQuery construct a parent object rather than raw…
Nidal-Bakir Apr 9, 2023
7819877
fix: _ParseRelationOperation toJson() for API Request uses value rath…
Nidal-Bakir Apr 10, 2023
1c3da62
fix: _ParseRelation getting targetClass from 'className' json key rat…
Nidal-Bakir Apr 10, 2023
e86de80
test: add tests for ParseRelation
Nidal-Bakir Apr 10, 2023
beef0c6
fix: containsValue in parseBase not accounting for _Valuable objects
Nidal-Bakir Apr 10, 2023
a1acc28
test: add tests for ParseBase, improve array and relation tests
Nidal-Bakir Apr 10, 2023
41944fe
test: add tests for fromJsonForManualObject in ParseBase
Nidal-Bakir Apr 10, 2023
cceea8f
test: add tests for empty value for API request in ParseRelation
Nidal-Bakir Apr 10, 2023
a6aa7cc
style: explicitly call toJson() for ParseGeoPoint and ParseFileBase i…
Nidal-Bakir Apr 11, 2023
d95f40f
docs: add documentation for _ParseOperation abstract class
Nidal-Bakir Apr 11, 2023
8a8fe62
fix: unset not include parseError object in the ParseResponse in case…
Nidal-Bakir Apr 12, 2023
e239514
test: test for error from ParseNetworkResponse
Nidal-Bakir Apr 12, 2023
ad160ee
test: add test for when the user call getRelation on key holds value …
Nidal-Bakir Apr 12, 2023
fc1335d
test: add test for error from the server in update() function
Nidal-Bakir Apr 12, 2023
c6c6e97
docs: add documentation for _Valuable interface
Nidal-Bakir Apr 12, 2023
33d6171
refactor: remove duplicate logic from parse operations
Nidal-Bakir Apr 12, 2023
9ab4fa7
feat: add new function to ParseRelation addAll and removeAll that acc…
Nidal-Bakir Apr 13, 2023
bfd67e4
docs: add and fix some documentations in ParseBase
Nidal-Bakir Apr 13, 2023
932f694
docs: add and fix some documentations in ParseObject
Nidal-Bakir Apr 13, 2023
4fb5535
docs: add documentations for parse operations classes
Nidal-Bakir Apr 13, 2023
bc7224f
chore: bump the Dart sdk version to 5.0.0 and add CHANGELOG entry
Nidal-Bakir Apr 21, 2023
a8133e7
Update packages/dart/CHANGELOG.md
Nidal-Bakir May 7, 2023
d9548e2
add new version to changelog
mtrezza May 9, 2023
6da8e1c
Merge branch 'master' into fix_parse_op
Nidal-Bakir May 12, 2023
7a2c480
Merge branch 'master' into fix_parse_op
Nidal-Bakir May 12, 2023
b59caa1
Merge branch 'master' into fix_parse_op
mtrezza May 13, 2023
bf8b111
Update CHANGELOG.md
mtrezza May 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

### BREAKING CHANGES

* The minimum required Dart SDK version is 2.18.0 ([#867](https://github.com/parse-community/Parse-SDK-Flutter/pull/867))
* The minimum required Dart SDK version is 2.18.0. ([#867](https://github.com/parse-community/Parse-SDK-Flutter/pull/867))
* Performing an atomic update on a key of a Parse Object now returns the prospective value, instead of a map of the operation that will be sent to the server; for example for a Parse Object `obj` with a key `count`, the atomic update `obj.setIncrement('count', 1);` previously returned the value `{__op: Increment, amount: 1}` but now returns the prospective result of the operation, which would be `1` if the key's previous value was `0`. ([#860](https://github.com/parse-community/Parse-SDK-Flutter/pull/860))

### Bug Fixes

* Incorrect Dart and Flutter SDKs compatibility range ([#867](https://github.com/parse-community/Parse-SDK-Flutter/pull/867))
* Setting atomic operation on Parse Object returns operation instead of prospective value ([#860](https://github.com/parse-community/Parse-SDK-Flutter/pull/860))

## [4.0.2](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-4.0.1...dart-4.0.2) (2023-03-23)

Expand Down
17 changes: 15 additions & 2 deletions packages/dart/lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ library flutter_parse_sdk;

import 'dart:async';
import 'dart:convert';
import 'package:universal_io/io.dart';
import 'dart:math';
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:dio/dio.dart';
import 'package:meta/meta.dart';
import 'package:mime_type/mime_type.dart';
Expand All @@ -14,6 +15,7 @@ import 'package:sembast/sembast_io.dart';
import 'package:sembast_web/sembast_web.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:universal_io/io.dart';
import 'package:uuid/uuid.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:xxtea/xxtea.dart';
Expand All @@ -34,20 +36,30 @@ part 'src/network/parse_connectivity.dart';
part 'src/network/parse_live_query.dart';
part 'src/network/parse_query.dart';
part 'src/objects/parse_acl.dart';
part 'src/objects/parse_array.dart';
part 'src/objects/parse_base.dart';
part 'src/objects/parse_cloneable.dart';
part 'src/objects/parse_config.dart';
part 'src/objects/parse_error.dart';
part 'src/objects/parse_file.dart';
part 'src/objects/parse_number.dart';
part 'src/objects/parse_file_base.dart';
part 'src/objects/parse_file_web.dart';
part 'src/objects/parse_function.dart';
part 'src/objects/parse_geo_point.dart';
part 'src/objects/parse_installation.dart';
part 'src/objects/parse_merge.dart';
part 'src/objects/parse_object.dart';
part 'src/objects/parse_exception.dart';
part 'src/objects/parse_operation/parse_add_operation.dart';
part 'src/objects/parse_operation/parse_add_relation_operation.dart';
part 'src/objects/parse_operation/parse_add_unique_operation.dart';
part 'src/objects/parse_operation/parse_increment_operation.dart';
part 'src/objects/parse_operation/parse_operation.dart';
part 'src/objects/parse_operation/parse_remove_operation.dart';
part 'src/objects/parse_operation/parse_remove_relation_operation.dart';
part 'src/objects/parse_relation.dart';
part 'src/objects/parse_response.dart';
part 'src/objects/parse_save_state_aware_child.dart';
part 'src/objects/parse_session.dart';
part 'src/objects/parse_user.dart';
part 'src/objects/response/parse_error_response.dart';
Expand All @@ -66,6 +78,7 @@ part 'src/utils/parse_live_list.dart';
part 'src/utils/parse_logger.dart';
part 'src/utils/parse_login_helpers.dart';
part 'src/utils/parse_utils.dart';
part 'src/utils/valuable.dart';

class Parse {
bool _hasBeenInitialized = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of flutter_parse_sdk;

// Library
const String keySdkVersion = '4.0.2';
const String keySdkVersion = '5.0.0';
const String keyLibraryName = 'Flutter Parse SDK';

// End Points
Expand Down
17 changes: 16 additions & 1 deletion packages/dart/lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class QueryBuilder<T extends ParseObject> {
T object;
List<MapEntry<String, dynamic>> queries = <MapEntry<String, dynamic>>[];
final Map<String, dynamic> limiters = <String, dynamic>{};
final Map<String, dynamic> extraOptions = <String, dynamic>{};

/// Used by ParseRelation getQuery()
void setRedirectClassNameForKey(String key) {
extraOptions['redirectClassNameForKey'] = key;
}

/// Adds a limit to amount of results return from Parse
void setLimit(int limit) {
Expand Down Expand Up @@ -408,7 +414,7 @@ class QueryBuilder<T extends ParseObject> {
/// Builds the query for Parse
String buildQuery() {
queries = _checkForMultipleColumnInstances(queries);
return 'where={${buildQueries(queries)}}${getLimiters(limiters)}';
return 'where={${buildQueries(queries)}}${getLimiters(limiters)}${getExtraOptions(extraOptions)}';
}

/// Builds the query relational for Parse
Expand Down Expand Up @@ -528,6 +534,15 @@ class QueryBuilder<T extends ParseObject> {
return result;
}

/// Adds extra options to the query
String getExtraOptions(Map<String, dynamic> map) {
String result = '';
map.forEach((String key, dynamic value) {
result = '$result&$key=$value';
});
return result;
}

/// Adds the limiters to the query relational, i.e. skip=10, limit=10
String getLimitersRelational(Map<String, dynamic> map) {
String result = '';
Expand Down
121 changes: 121 additions & 0 deletions packages/dart/lib/src/objects/parse_array.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
part of flutter_parse_sdk;

class _ParseArray implements _Valuable<List>, _ParseSaveStateAwareChild {
_ParseArray({this.setMode = false});

bool setMode;

List _savedArray = [];
List estimatedArray = [];

set savedArray(List array) {
_savedArray = array.toList();
estimatedArray = array.toList();
}

List get savedArray => _savedArray;

_ParseArrayOperation? lastPreformedOperation;

_ParseArray preformArrayOperation(
_ParseArrayOperation arrayOperation,
) {
arrayOperation.mergeWithPrevious(lastPreformedOperation ?? this);

lastPreformedOperation = arrayOperation;

estimatedArray = lastPreformedOperation!.value.toList();

if (setMode) {
lastPreformedOperation = null;
}

return this;
}

Object toJson({bool full = false}) {
if (full) {
return {
'className': 'ParseArray',
'estimatedArray': parseEncode(estimatedArray, full: full),
'savedArray': parseEncode(_savedArray, full: full),
'lastPreformedOperation': lastPreformedOperation?.toJson(full: full)
};
}

return lastPreformedOperation?.toJson(full: full) ??
parseEncode(estimatedArray, full: full);
}

factory _ParseArray.fromFullJson(Map<String, dynamic> json) {
return _ParseArray()
.._savedArray = parseDecode(json['savedArray'])
..estimatedArray = parseDecode(json['estimatedArray'])
..lastPreformedOperation = json['lastPreformedOperation'] == null
? null
: _ParseArrayOperation.fromFullJson(json['lastPreformedOperation']);
}

@override
List getValue() {
return estimatedArray.toList();
}

_ParseArrayOperation? _lastPreformedOperationBeforeSaving;
List? _estimatedArrayBeforeSaving;

@override
@mustCallSuper
void onSaved() {
setMode = false;
_savedArray.clear();
_savedArray.addAll(_estimatedArrayBeforeSaving ?? []);
_estimatedArrayBeforeSaving = null;

if (_lastPreformedOperationBeforeSaving == lastPreformedOperation) {
// No operations were performed during the save process
lastPreformedOperation = null;
} else {
// remove the saved objects and keep the new added objects while saving
if (lastPreformedOperation is _ParseRemoveOperation) {
lastPreformedOperation?.valueForApiRequest
.retainWhere((e) => _savedArray.contains(e));
} else {
lastPreformedOperation?.valueForApiRequest
.removeWhere((e) => _savedArray.contains(e));
}
}

_lastPreformedOperationBeforeSaving = null;
}

@override
@mustCallSuper
void onSaving() {
_lastPreformedOperationBeforeSaving = lastPreformedOperation;
_estimatedArrayBeforeSaving = estimatedArray.toList();
}

@override
@mustCallSuper
void onRevertSaving() {
_lastPreformedOperationBeforeSaving = null;
_estimatedArrayBeforeSaving = null;
}

@override
@mustCallSuper
void onErrorSaving() {
_lastPreformedOperationBeforeSaving = null;
_estimatedArrayBeforeSaving = null;
}

@override
@mustCallSuper
void onClearUnsaved() {
estimatedArray = savedArray;
lastPreformedOperation = null;
_lastPreformedOperationBeforeSaving = null;
_estimatedArrayBeforeSaving = null;
}
}
Loading