Skip to content
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

feat: Sync skip delete #696

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 5.1.0
- feat: Introduce skipDeletesUntil for sync:from verb
## 5.0.2
- fix: Add "publicKeyHash" and "hashingAlgo" type to metadata.
- build[deps]: Upgraded the following package:
Expand Down
12 changes: 12 additions & 0 deletions packages/at_commons/lib/src/verb/sync_verb_builder.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take this opportunity to add /// documentation for all of the parameters (commitId, regex, limit, isPaginated, skipDeletesUntil)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the dart docs


@override
String buildCommand() {
StringBuffer serverCommandBuffer = StringBuffer('sync:');
Expand All @@ -19,6 +28,9 @@ class SyncVerbBuilder implements VerbBuilder {
if (isPaginated) {
serverCommandBuffer.write(':limit:$limit');
}
if (skipDeletesUntil != null) {
serverCommandBuffer.write(':skipDeletesUntil:$skipDeletesUntil');
}
if (regex != null && regex!.isNotEmpty) {
serverCommandBuffer.write(':$regex');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/at_commons/lib/src/verb/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VerbSyntax {
r'^stats(?<statId>:((?!0)\d+)?(,(\d+))*)?(:(?<regex>(?<=:3:|:15:).+))?$';
static const sync = r'^sync:(?<from_commit_seq>[0-9]+|-1)(:(?<regex>.+))?$';
static const syncFrom =
r'^sync:from:(?<from_commit_seq>[0-9]+|-1)(:limit:(?<limit>\d+))(:(?<regex>.+))?$';
r'^sync:from:(?<from_commit_seq>[0-9]+|-1)(:limit:(?<limit>\d+))?(:skipDeletesUntil:(?<skipDeletesUntil>\d+))?(:(?<regex>.+))?$';

@visibleForTesting
static const metadataFragment = r'(:ttl:(?<ttl>(-?)\d+))?'
Expand Down
2 changes: 1 addition & 1 deletion packages/at_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.2
version: 5.1.0
repository: https://github.com/atsign-foundation/at_libraries
homepage: https://atsign.dev

Expand Down
13 changes: 13 additions & 0 deletions packages/at_commons/test/sync_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
..skipDeletesUntil = 20;
var command = syncVerbBuilder.buildCommand();
expect(command, 'sync:from:-1:limit:5:skipDeletesUntil:20\n');
var regex = RegExp(VerbSyntax.syncFrom);
command = command.replaceAll('\n', '');
assert(regex.hasMatch(command));
});
}