Skip to content

Commit

Permalink
Merge pull request #242 from atsign-foundation/add_isLocal_to_verb_bu…
Browse files Browse the repository at this point in the history
…ilder

feat: add isLocal to verb builders
  • Loading branch information
sitaram-kalluri authored Oct 19, 2022
2 parents 2d338d5 + 2f31bef commit 1390a35
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.28
* feat: Introduce the local key type
## 3.0.27
* feat: Implement the `==` and `hashCode` methods for AtKey, AtValue and Metadata classes
## 3.0.26
Expand Down
2 changes: 1 addition & 1 deletion at_commons/lib/at_builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export 'package:at_commons/src/verb/syntax.dart';
export 'package:at_commons/src/verb/update_verb_builder.dart';
export 'package:at_commons/src/verb/verb_builder.dart';
export 'package:at_commons/src/verb/from_verb_builder.dart';
export 'package:at_commons/src/verb/notify_fetch_verb_builder.dart';
export 'package:at_commons/src/verb/notify_fetch_verb_builder.dart';
7 changes: 7 additions & 0 deletions at_commons/lib/src/verb/llookup_verb_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ class LLookupVerbBuilder implements VerbBuilder {

String? operation;

/// Indicates if the key is local
/// If the key is local, the key does not sync between cloud and local secondary
bool isLocal = false;

@override
String buildCommand() {
var command = 'llookup:';
if (operation != null) {
command += '$operation:';
}
if (isLocal) {
command += 'local:';
}
if (isCached) {
command += 'cached:';
}
Expand Down
14 changes: 12 additions & 2 deletions at_commons/lib/src/verb/update_verb_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class UpdateVerbBuilder implements VerbBuilder {
///If the public data contains new line (\n) character, the data will be encoded and encoding will be set to type of encoding
String? encoding;

/// Indicates if the key is local
/// If the key is local, the key does not sync between cloud and local secondary
bool isLocal = false;

@override
String buildCommand() {
if (isJson) {
Expand Down Expand Up @@ -142,13 +146,19 @@ class UpdateVerbBuilder implements VerbBuilder {
if (encoding != null && encoding!.isNotEmpty) {
command += '$ENCODING:$encoding';
}
if (isPublic) {
// The key can only be
// 1. a local key
// 2. a public key or
// 3. a shared key
// The key is mutually exclusive between isLocal, isPublic and sharedWith
if (isLocal) {
command += 'local:';
} else if (isPublic) {
command += 'public:';
} else if (sharedWith != null) {
command += '${VerbUtil.formatAtSign(sharedWith)}:';
}
command += atKey!;

if (sharedBy != null) {
command += '${VerbUtil.formatAtSign(sharedBy)}';
}
Expand Down
2 changes: 1 addition & 1 deletion 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: 3.0.27
version: 3.0.28
repository: https://github.com/atsign-foundation/at_tools
homepage: https://atsign.dev

Expand Down
3 changes: 2 additions & 1 deletion at_commons/test/at_key_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ void main() {
..atSign = '@alice'
..enforceNamespace = true);
expect(validationResult.isValid, false);
expect(validationResult.failureReason, 'local:phone@alice is not a valid key');
expect(validationResult.failureReason,
'local:phone@alice is not a valid key');
});
});
}
3 changes: 2 additions & 1 deletion at_commons/test/at_key_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void main() {
});

test('Test to verify local key type with namespace', () {
var keyType = AtKey.getKeyType('local:latestNotification.wavi@bob', enforceNameSpace: true);
var keyType = AtKey.getKeyType('local:latestNotification.wavi@bob',
enforceNameSpace: true);
expect(keyType, equals(KeyType.localKey));
});
});
Expand Down
6 changes: 4 additions & 2 deletions at_commons/test/notify_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ void main() {
expect(verbParams['notificationId'], '123');
});

test('Negative test to verify to notify:fetch when notification id not set', () {
test('Negative test to verify to notify:fetch when notification id not set',
() {
var notifyFetch = NotifyFetchVerbBuilder();
expect(() => notifyFetch.buildCommand(),
throwsA(predicate((dynamic e) => e is InvalidSyntaxException)));
});

test('Negative test to verify to notify:fetch when empty string is set', () {
test('Negative test to verify to notify:fetch when empty string is set',
() {
var notifyFetch = NotifyFetchVerbBuilder()..notificationId = '';
expect(() => notifyFetch.buildCommand(),
throwsA(predicate((dynamic e) => e is InvalidSyntaxException)));
Expand Down
10 changes: 10 additions & 0 deletions at_commons/test/update_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ void main() {
expect(updateBuilder.buildCommand(),
'update:sharedKeyEnc:abc:pubKeyCS:123:@bob:email@alice [email protected]\n');
});

test('verify local key command', () {
var updateBuilder = UpdateVerbBuilder()
..value = '[email protected]'
..atKey = 'email'
..sharedBy = 'alice'
..isLocal = true;
expect(updateBuilder.buildCommand(),
'update:local:email@alice [email protected]\n');
});
});

group('A group of update verb builder tests to check update metadata command',
Expand Down

0 comments on commit 1390a35

Please sign in to comment.