diff --git a/at_commons/CHANGELOG.md b/at_commons/CHANGELOG.md index 51deef26..9ea3241c 100644 --- a/at_commons/CHANGELOG.md +++ b/at_commons/CHANGELOG.md @@ -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 diff --git a/at_commons/lib/at_builders.dart b/at_commons/lib/at_builders.dart index def381eb..43fc373e 100644 --- a/at_commons/lib/at_builders.dart +++ b/at_commons/lib/at_builders.dart @@ -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'; \ No newline at end of file +export 'package:at_commons/src/verb/notify_fetch_verb_builder.dart'; diff --git a/at_commons/lib/src/verb/llookup_verb_builder.dart b/at_commons/lib/src/verb/llookup_verb_builder.dart index 01e24825..bfc3b37d 100644 --- a/at_commons/lib/src/verb/llookup_verb_builder.dart +++ b/at_commons/lib/src/verb/llookup_verb_builder.dart @@ -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:'; } diff --git a/at_commons/lib/src/verb/update_verb_builder.dart b/at_commons/lib/src/verb/update_verb_builder.dart index 79e4e0f8..c972eb63 100644 --- a/at_commons/lib/src/verb/update_verb_builder.dart +++ b/at_commons/lib/src/verb/update_verb_builder.dart @@ -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) { @@ -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)}'; } diff --git a/at_commons/pubspec.yaml b/at_commons/pubspec.yaml index 148fda92..455e3d4c 100644 --- a/at_commons/pubspec.yaml +++ b/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: 3.0.27 +version: 3.0.28 repository: https://github.com/atsign-foundation/at_tools homepage: https://atsign.dev diff --git a/at_commons/test/at_key_test.dart b/at_commons/test/at_key_test.dart index 078cefd7..b48266f6 100644 --- a/at_commons/test/at_key_test.dart +++ b/at_commons/test/at_key_test.dart @@ -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'); }); }); } diff --git a/at_commons/test/at_key_type_test.dart b/at_commons/test/at_key_type_test.dart index 09e4da12..c1c012c4 100644 --- a/at_commons/test/at_key_type_test.dart +++ b/at_commons/test/at_key_type_test.dart @@ -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)); }); }); diff --git a/at_commons/test/notify_verb_builder_test.dart b/at_commons/test/notify_verb_builder_test.dart index 479b2e77..a6d02830 100644 --- a/at_commons/test/notify_verb_builder_test.dart +++ b/at_commons/test/notify_verb_builder_test.dart @@ -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))); diff --git a/at_commons/test/update_verb_builder_test.dart b/at_commons/test/update_verb_builder_test.dart index 130fceed..7a6048ef 100644 --- a/at_commons/test/update_verb_builder_test.dart +++ b/at_commons/test/update_verb_builder_test.dart @@ -36,6 +36,16 @@ void main() { expect(updateBuilder.buildCommand(), 'update:sharedKeyEnc:abc:pubKeyCS:123:@bob:email@alice alice@atsign.com\n'); }); + + test('verify local key command', () { + var updateBuilder = UpdateVerbBuilder() + ..value = 'alice@atsign.com' + ..atKey = 'email' + ..sharedBy = 'alice' + ..isLocal = true; + expect(updateBuilder.buildCommand(), + 'update:local:email@alice alice@atsign.com\n'); + }); }); group('A group of update verb builder tests to check update metadata command',