From 23fa31cfd63810a3501d8c7d88d78f2e20d51b61 Mon Sep 17 00:00:00 2001 From: Murali Date: Tue, 15 Oct 2024 11:46:02 +0530 Subject: [PATCH 1/6] feat: add skipDeletes to sync syntax --- packages/at_commons/lib/src/verb/syntax.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 0a6e3dde..2e565035 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -24,9 +24,9 @@ class VerbSyntax { r'^config:(?:(?<=config:)block:(?add|remove|show)(?:(?<=show)\s?$|(?:(?<=add|remove):(?(?:@[^:@\s]+)( (?:@[^\s@]+))*$))))|(?:(?<=config:)(?set|reset|print):(?.+)$)'; static const stats = r'^stats(?:((?!0)\d+)?(,(\d+))*)?(:(?(?<=:3:|:15:).+))?$'; - static const sync = r'^sync:(?[0-9]+|-1)(:(?.+))?$'; + static const sync = r'^sync:(?[0-9]+|-1):(skipDeletes:(?true|false):)?(:(?.+))?$'; static const syncFrom = - r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+))(:(?.+))?$'; + r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+)):(skipDeletes:(?true|false):)?(:(?.+))?$'; @visibleForTesting static const metadataFragment = r'(:ttl:(?(-?)\d+))?' From ac09383daaddac93f02bb90bbb5382867e33b0db Mon Sep 17 00:00:00 2001 From: Murali Date: Thu, 17 Oct 2024 13:28:12 +0530 Subject: [PATCH 2/6] fix: sync kip deletes syntax change and unit test --- packages/at_commons/lib/at_commons.dart | 1 + .../at_commons/lib/src/verb/sync_verb_builder.dart | 5 +++++ packages/at_commons/lib/src/verb/syntax.dart | 4 ++-- .../at_commons/test/sync_verb_builder_test.dart | 13 +++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/at_commons/lib/at_commons.dart b/packages/at_commons/lib/at_commons.dart index cecbd664..871c3b02 100644 --- a/packages/at_commons/lib/at_commons.dart +++ b/packages/at_commons/lib/at_commons.dart @@ -29,6 +29,7 @@ export 'package:at_commons/src/verb/verb_util.dart'; export 'package:at_commons/src/auth/auth_mode.dart'; export 'package:at_commons/src/verb/enroll_params.dart'; export 'package:at_commons/src/enroll/enrollment.dart'; +export 'package:at_commons/src/utils/at_key_regex_utils.dart'; @experimental export 'package:at_commons/src/telemetry/at_telemetry.dart'; export 'package:at_commons/src/utils/string_utils.dart'; diff --git a/packages/at_commons/lib/src/verb/sync_verb_builder.dart b/packages/at_commons/lib/src/verb/sync_verb_builder.dart index 0bbeda9a..6fbbc9e3 100644 --- a/packages/at_commons/lib/src/verb/sync_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/sync_verb_builder.dart @@ -9,6 +9,8 @@ class SyncVerbBuilder implements VerbBuilder { bool isPaginated = false; + bool skipDeletes = false; + @override String buildCommand() { StringBuffer serverCommandBuffer = StringBuffer('sync:'); @@ -19,6 +21,9 @@ class SyncVerbBuilder implements VerbBuilder { if (isPaginated) { serverCommandBuffer.write(':limit:$limit'); } + if (skipDeletes) { + serverCommandBuffer.write(':skipDeletes:true'); + } if (regex != null && regex!.isNotEmpty) { serverCommandBuffer.write(':$regex'); } diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 2e565035..68fe0d49 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -24,9 +24,9 @@ class VerbSyntax { r'^config:(?:(?<=config:)block:(?add|remove|show)(?:(?<=show)\s?$|(?:(?<=add|remove):(?(?:@[^:@\s]+)( (?:@[^\s@]+))*$))))|(?:(?<=config:)(?set|reset|print):(?.+)$)'; static const stats = r'^stats(?:((?!0)\d+)?(,(\d+))*)?(:(?(?<=:3:|:15:).+))?$'; - static const sync = r'^sync:(?[0-9]+|-1):(skipDeletes:(?true|false):)?(:(?.+))?$'; + static const sync = r'^sync:(?[0-9]+|-1)?(:(?.+))?$'; static const syncFrom = - r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+)):(skipDeletes:(?true|false):)?(:(?.+))?$'; + r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+))?(:skipDeletes:(?true|false))?(:(?.+))?$'; @visibleForTesting static const metadataFragment = r'(:ttl:(?(-?)\d+))?' diff --git a/packages/at_commons/test/sync_verb_builder_test.dart b/packages/at_commons/test/sync_verb_builder_test.dart index 3f4a6f9c..8520aca1 100644 --- a/packages/at_commons/test/sync_verb_builder_test.dart +++ b/packages/at_commons/test/sync_verb_builder_test.dart @@ -69,4 +69,17 @@ void main() { command = command.replaceAll('\n', ''); assert(regex.hasMatch(command)); }); + + test('build sync stream verb command with skipDeletes', () { + var syncVerbBuilder = SyncVerbBuilder() + ..commitId = -1 + ..isPaginated = true + ..limit = 5 + ..skipDeletes = true; + var command = syncVerbBuilder.buildCommand(); + expect(command, 'sync:from:-1:limit:5:skipDeletes:true\n'); + var regex = RegExp(VerbSyntax.syncFrom); + command = command.replaceAll('\n', ''); + assert(regex.hasMatch(command)); + }); } From 436daec57088030c0d080456267bc84941227283 Mon Sep 17 00:00:00 2001 From: Murali Date: Thu, 17 Oct 2024 13:36:52 +0530 Subject: [PATCH 3/6] fix: sync syntax issue fix --- packages/at_commons/lib/src/verb/syntax.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 68fe0d49..949d1f0f 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -24,7 +24,7 @@ class VerbSyntax { r'^config:(?:(?<=config:)block:(?add|remove|show)(?:(?<=show)\s?$|(?:(?<=add|remove):(?(?:@[^:@\s]+)( (?:@[^\s@]+))*$))))|(?:(?<=config:)(?set|reset|print):(?.+)$)'; static const stats = r'^stats(?:((?!0)\d+)?(,(\d+))*)?(:(?(?<=:3:|:15:).+))?$'; - static const sync = r'^sync:(?[0-9]+|-1)?(:(?.+))?$'; + static const sync = r'^sync:(?[0-9]+|-1)(:(?.+))?$'; static const syncFrom = r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+))?(:skipDeletes:(?true|false))?(:(?.+))?$'; From 2b7de2aa5610607b39c827f242d2db346e0154da Mon Sep 17 00:00:00 2001 From: Murali Date: Tue, 22 Oct 2024 12:18:07 +0530 Subject: [PATCH 4/6] fix: modified changelog and pubspec --- packages/at_commons/CHANGELOG.md | 2 ++ packages/at_commons/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 667c6b02..5b974395 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,3 +1,5 @@ +## 5.0.2 +- feat: Introduce skipDeletes for sync:from verb ## 5.0.1 - fix: export regex utils class ## 5.0.0 diff --git a/packages/at_commons/pubspec.yaml b/packages/at_commons/pubspec.yaml index 2ad37a38..d35ded13 100644 --- a/packages/at_commons/pubspec.yaml +++ b/packages/at_commons/pubspec.yaml @@ -1,6 +1,6 @@ name: at_commons description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform. -version: 5.0.1 +version: 5.0.2 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.dev From d6678ef97222fe4e0bf94b80645a950225ec44e8 Mon Sep 17 00:00:00 2001 From: Murali Date: Tue, 5 Nov 2024 10:54:54 +0530 Subject: [PATCH 5/6] fix: renamed skipDeletes to skipDeletesUntil --- packages/at_commons/lib/src/verb/sync_verb_builder.dart | 6 +++--- packages/at_commons/lib/src/verb/syntax.dart | 2 +- packages/at_commons/test/sync_verb_builder_test.dart | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/at_commons/lib/src/verb/sync_verb_builder.dart b/packages/at_commons/lib/src/verb/sync_verb_builder.dart index 6fbbc9e3..8e1487e5 100644 --- a/packages/at_commons/lib/src/verb/sync_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/sync_verb_builder.dart @@ -9,7 +9,7 @@ class SyncVerbBuilder implements VerbBuilder { bool isPaginated = false; - bool skipDeletes = false; + int? skipDeletesUntil; @override String buildCommand() { @@ -21,8 +21,8 @@ class SyncVerbBuilder implements VerbBuilder { if (isPaginated) { serverCommandBuffer.write(':limit:$limit'); } - if (skipDeletes) { - serverCommandBuffer.write(':skipDeletes:true'); + if (skipDeletesUntil != null) { + serverCommandBuffer.write(':skipDeletesUntil:$skipDeletesUntil'); } if (regex != null && regex!.isNotEmpty) { serverCommandBuffer.write(':$regex'); diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 949d1f0f..79f5d401 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -26,7 +26,7 @@ class VerbSyntax { r'^stats(?:((?!0)\d+)?(,(\d+))*)?(:(?(?<=:3:|:15:).+))?$'; static const sync = r'^sync:(?[0-9]+|-1)(:(?.+))?$'; static const syncFrom = - r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+))?(:skipDeletes:(?true|false))?(:(?.+))?$'; + r'^sync:from:(?[0-9]+|-1)(:limit:(?\d+))?(:skipDeletesUntil:(?\d+))?(:(?.+))?$'; @visibleForTesting static const metadataFragment = r'(:ttl:(?(-?)\d+))?' diff --git a/packages/at_commons/test/sync_verb_builder_test.dart b/packages/at_commons/test/sync_verb_builder_test.dart index 8520aca1..1d7aa518 100644 --- a/packages/at_commons/test/sync_verb_builder_test.dart +++ b/packages/at_commons/test/sync_verb_builder_test.dart @@ -75,9 +75,9 @@ void main() { ..commitId = -1 ..isPaginated = true ..limit = 5 - ..skipDeletes = true; + ..skipDeletesUntil = 20; var command = syncVerbBuilder.buildCommand(); - expect(command, 'sync:from:-1:limit:5:skipDeletes:true\n'); + expect(command, 'sync:from:-1:limit:5:skipDeletesUntil:20\n'); var regex = RegExp(VerbSyntax.syncFrom); command = command.replaceAll('\n', ''); assert(regex.hasMatch(command)); From fecca95e21a890cb23dc048735c13b3681723524 Mon Sep 17 00:00:00 2001 From: Murali Date: Mon, 2 Dec 2024 21:04:31 +0530 Subject: [PATCH 6/6] fix: review comments --- packages/at_commons/CHANGELOG.md | 2 +- packages/at_commons/lib/src/verb/sync_verb_builder.dart | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 1b067346..5330acdf 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,5 +1,5 @@ ## 5.1.0 -- feat: Introduce skipDeletes for sync:from verb +- feat: Introduce skipDeletesUntil for sync:from verb ## 5.0.2 - fix: Add "publicKeyHash" and "hashingAlgo" type to metadata. - build[deps]: Upgraded the following package: diff --git a/packages/at_commons/lib/src/verb/sync_verb_builder.dart b/packages/at_commons/lib/src/verb/sync_verb_builder.dart index 8e1487e5..3495dde4 100644 --- a/packages/at_commons/lib/src/verb/sync_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/sync_verb_builder.dart @@ -1,14 +1,21 @@ import 'package:at_commons/at_builders.dart'; class SyncVerbBuilder implements VerbBuilder { + /// commitId from which entries will be synced from server to client late int commitId; + /// if regex is set, then only keys matching the regex will be synced from server to client String? regex; + @Deprecated( + 'This field is not used anymore even though it is set in client. Remove this in next major release') int limit = 10; + @Deprecated( + 'This field is not used anymore even though it is set in client. Remove this in next major release') bool isPaginated = false; + /// if skipDeletesUntil is set, then delete commit entries whose commitId is <= skipDeletesUntil will not be synced from server to client int? skipDeletesUntil; @override