-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix: at_commons 4.0.0 uptake in at_Client #1192
Changes from 11 commits
1de43a3
82ec47f
85cbb24
4343fe5
12ff4c9
ed3b11d
ebe4008
7aa87ac
504c9c0
1c20bce
cef5f61
57cb917
495696a
68aa6f4
894dc2f
341a0a8
03e9ab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
name: at_client_sdk | ||
|
||
packages: | ||
- packages/* | ||
- packages/at_client_mobile | ||
- packages/*/example | ||
|
||
- tests/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,9 @@ class DefaultKeyMaker implements KeyMaker { | |
return AtKey() | ||
..key = '$keyId.$collectionName.atcollectionmodel.$namespace' | ||
..metadata = Metadata() | ||
..metadata!.ccd = objectLifeCycleOptions?.cascadeDelete ?? true | ||
..metadata!.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds | ||
..metadata!.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds | ||
..metadata.ccd = objectLifeCycleOptions?.cascadeDelete ?? true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In at_commons-> AtKey, updated the "metadata" field from nullable field (removed "?"). With the change, the field is defaulted to Metadata instance - "Metadata metadata = Metadata();" |
||
..metadata.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds | ||
..metadata.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds | ||
..sharedBy = _getAtClient().getCurrentAtSign(); | ||
} | ||
|
||
|
@@ -36,10 +36,10 @@ class DefaultKeyMaker implements KeyMaker { | |
..key = '$keyId.$collectionName.atcollectionmodel.$namespace' | ||
..sharedWith = sharedWith | ||
..metadata = Metadata() | ||
..metadata!.ttr = ttrInSeconds ?? -1 | ||
..metadata!.ccd = objectLifeCycleOptions?.cascadeDelete ?? true | ||
..metadata!.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds | ||
..metadata!.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds | ||
..metadata.ttr = ttrInSeconds ?? -1 | ||
..metadata.ccd = objectLifeCycleOptions?.cascadeDelete ?? true | ||
..metadata.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds | ||
..metadata.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds | ||
..sharedBy = _getAtClient().getCurrentAtSign(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,23 +294,8 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
|
||
Future<bool> _delete(AtKey atKey, | ||
{DeleteRequestOptions? deleteRequestOptions}) async { | ||
// If metadata is null, initialize metadata | ||
atKey.metadata ??= Metadata(); | ||
String keyWithNamespace; | ||
if (atKey.metadata!.namespaceAware) { | ||
keyWithNamespace = AtClientUtil.getKeyWithNameSpace(atKey, _preference!); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the namespace fixing no longer required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By assigning atKey directly to the verb builder, key construction utilizes AtKey.toString(), appending the namespace to the key. For the key we do not want namespace to be appended, leaving the namespace fields unset or initializing them to an empty string will suffice. However, when the user doesn't set a namespace for the AtKey, the earlier practice involved appending the namespace from the AtClientPreferences when namespaceAware is set to "true" is missing here. Will add the code where if atKey.namespace is null or empty and namespaceAware is true, then set the namespace from AtClientPreference.namespace |
||
} else { | ||
keyWithNamespace = atKey.key!; | ||
} | ||
atKey.sharedBy ??= _atSign; | ||
var builder = DeleteVerbBuilder() | ||
..isLocal = atKey.isLocal | ||
..isCached = atKey.metadata!.isCached | ||
..isPublic = | ||
(atKey.metadata!.isPublic == null) ? false : atKey.metadata!.isPublic! | ||
..sharedWith = atKey.sharedWith | ||
..atKey = keyWithNamespace | ||
..sharedBy = atKey.sharedBy; | ||
var builder = DeleteVerbBuilder()..atKey = atKey; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fields of AtKey are now substituted with AtKey instances in all verb builders. The atKey object is directly assigned, and the code responsible for assigning fields of atKey has been removed |
||
var secondary = getSecondary(); | ||
if (deleteRequestOptions != null && | ||
deleteRequestOptions.useRemoteAtServer) { | ||
|
@@ -441,10 +426,8 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
Future<AtResponse> putText(AtKey atKey, String value, | ||
{PutRequestOptions? putRequestOptions}) async { | ||
try { | ||
// Set the default metadata if not already set. | ||
atKey.metadata ??= Metadata(); | ||
// Setting metadata.isBinary to false for putText | ||
atKey.metadata!.isBinary = false; | ||
atKey.metadata.isBinary = false; | ||
return await _putInternal(atKey, value, putRequestOptions); | ||
} on AtException catch (e) { | ||
throw AtExceptionManager.createException(e); | ||
|
@@ -456,10 +439,8 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
Future<AtResponse> putBinary(AtKey atKey, List<int> value, | ||
{PutRequestOptions? putRequestOptions}) async { | ||
try { | ||
// Set the default metadata if not already set. | ||
atKey.metadata ??= Metadata(); | ||
// Setting metadata.isBinary to true for putBinary | ||
atKey.metadata!.isBinary = true; | ||
atKey.metadata.isBinary = true; | ||
// Base2e15.encode method converts the List<int> type to String. | ||
return await _putInternal( | ||
atKey, Base2e15.encode(value), putRequestOptions); | ||
|
@@ -470,7 +451,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
|
||
@visibleForTesting | ||
ensureLowerCase(AtKey atKey) { | ||
if ((atKey.key != null && upperCaseRegex.hasMatch(atKey.key!)) || | ||
if (upperCaseRegex.hasMatch(atKey.key) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Atkey.key is modified as a non null variable in at_commons, removed the non-null assertion operator |
||
(atKey.namespace != null && | ||
upperCaseRegex.hasMatch(atKey.namespace!))) { | ||
_logger.finer('AtKey: ${atKey.toString()} previously contained upper case' | ||
|
@@ -487,12 +468,12 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
if (atKey.sharedBy.isNull) { | ||
atKey.sharedBy = _atSign; | ||
} | ||
if (atKey.metadata!.namespaceAware) { | ||
if (atKey.metadata.namespaceAware) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Atkey.metadata is modified as a non null variable (defaulted to "Metadata()"), removed the non-null assertion operator |
||
atKey.namespace ??= preference?.namespace; | ||
} | ||
|
||
if (preference!.atProtocolEmitted >= Version(2, 0, 0)) { | ||
atKey.metadata!.ivNonce ??= EncryptionUtil.generateIV(); | ||
atKey.metadata.ivNonce ??= EncryptionUtil.generateIV(); | ||
} | ||
ensureLowerCase(atKey); | ||
|
||
|
@@ -521,7 +502,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
|
||
//Get encryptionPrivateKey for public key to signData | ||
String? encryptionPrivateKey; | ||
if (atKey.metadata!.isPublic != null && atKey.metadata!.isPublic! == true) { | ||
if (atKey.metadata.isPublic == true) { | ||
encryptionPrivateKey = await _localSecondary?.getEncryptionPrivateKey(); | ||
} | ||
// Transform put request | ||
|
@@ -543,7 +524,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
} | ||
// Execute the verb builder | ||
var putResponse = await secondary.executeVerb(verbBuilder, | ||
sync: SyncUtil.shouldSync(atKey.key!)); | ||
sync: SyncUtil.shouldSync(atKey.key)); | ||
// If putResponse is null or empty, return AtResponse with isError set to true | ||
if (putResponse == null || putResponse.isEmpty) { | ||
return AtResponse()..isError = true; | ||
|
@@ -579,27 +560,17 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
@override | ||
Future<bool> putMeta(AtKey atKey) async { | ||
var updateKey = atKey.key; | ||
var metadata = atKey.metadata!; | ||
var metadata = atKey.metadata; | ||
if (metadata.namespaceAware) { | ||
updateKey = _getKeyWithNamespace(atKey.key!); | ||
updateKey = _getKeyWithNamespace(atKey.key); | ||
} | ||
var sharedWith = atKey.sharedWith; | ||
var builder = UpdateVerbBuilder(); | ||
builder | ||
..atKey = updateKey | ||
..sharedBy = _atSign | ||
..sharedWith = sharedWith | ||
..ttl = metadata.ttl | ||
..ttb = metadata.ttb | ||
..ttr = metadata.ttr | ||
..ccd = metadata.ccd | ||
..isBinary = metadata.isBinary | ||
..isEncrypted = metadata.isEncrypted | ||
..dataSignature = metadata.dataSignature | ||
..atKey = atKey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fields of AtKey are now substituted with AtKey instances in all verb builders. The atKey object is directly assigned, and the code responsible for assigning fields of atKey has been removed |
||
..operation = AtConstants.updateMeta; | ||
|
||
var updateMetaResult = await getSecondary() | ||
.executeVerb(builder, sync: SyncUtil.shouldSync(updateKey!)); | ||
.executeVerb(builder, sync: SyncUtil.shouldSync(updateKey)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Atkey.key is modified as a non null variable in at_commons, removed the non-null assertion operator |
||
return updateMetaResult != null; | ||
} | ||
|
||
|
@@ -768,9 +739,9 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
..key = key | ||
..sharedWith = sharedWithAtSign | ||
..metadata = Metadata() | ||
..metadata!.ttr = -1 | ||
..metadata.ttr = -1 | ||
// file transfer key will be deleted after 30 days | ||
..metadata!.ttl = 2592000000 | ||
..metadata.ttl = 2592000000 | ||
..sharedBy = _atSign; | ||
|
||
var notificationResult = await notificationService.notify( | ||
|
@@ -949,7 +920,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener { | |
PriorityEnum? priority, | ||
StrategyEnum? strategy, | ||
int? latestN, | ||
String? notifier = SYSTEM, | ||
String? notifier = AtConstants.system, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced the use of legacy at_constants (which are now removed from at_commons -4.0.0) with new references to new AtConstants file |
||
bool isDedicated = false}) async { | ||
AtKeyValidators.get().validate( | ||
atKey.toString(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,11 @@ class LookUpBuilderManager { | |
{GetRequestOptions? getRequestOptions}) { | ||
// If isPublic is true in metadata, the key is a public key, return PLookupVerbHandler. | ||
if (atKey.sharedBy != currentAtSign && | ||
(atKey.metadata != null && | ||
atKey.metadata!.isPublic! && | ||
!atKey.metadata!.isCached)) { | ||
(atKey.metadata.isPublic && !atKey.metadata.isCached)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since AtKey.metadata is not null and boolean fields in Metadata have default values instead of null, removed the null check and non null assertion operator |
||
final plookUpVerbBuilder = PLookupVerbBuilder() | ||
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy) | ||
..atKey = (AtKey() | ||
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)) | ||
..operation = 'all'; | ||
if (getRequestOptions != null && getRequestOptions.bypassCache == true) { | ||
plookUpVerbBuilder.bypassCache = true; | ||
|
@@ -24,12 +23,11 @@ class LookUpBuilderManager { | |
} | ||
// If sharedBy is not equal to currentAtSign and isCached is false, return LookupVerbHandler | ||
if (atKey.sharedBy != currentAtSign && | ||
(atKey.metadata != null && | ||
!atKey.metadata!.isCached && | ||
!atKey.metadata!.isPublic!)) { | ||
(!atKey.metadata.isCached && !atKey.metadata.isPublic)) { | ||
final lookupVerbBuilder = LookupVerbBuilder() | ||
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy) | ||
..atKey = (AtKey() | ||
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)) | ||
..auth = true | ||
..operation = 'all'; | ||
if (getRequestOptions != null && getRequestOptions.bypassCache == true) { | ||
|
@@ -38,16 +36,14 @@ class LookUpBuilderManager { | |
return lookupVerbBuilder; | ||
} | ||
return LLookupVerbBuilder() | ||
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy) | ||
..sharedWith = AtClientUtil.fixAtSign(atKey.sharedWith) | ||
..isPublic = (atKey.metadata != null && atKey.metadata?.isPublic != null) | ||
? atKey.metadata!.isPublic! | ||
: false | ||
..isCached = (atKey.metadata != null && atKey.metadata?.isCached != null) | ||
? atKey.metadata!.isCached | ||
: false | ||
..isLocal = atKey.isLocal | ||
..atKey = (AtKey() | ||
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference) | ||
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy) | ||
..sharedWith = AtClientUtil.fixAtSign(atKey.sharedWith) | ||
..metadata = (Metadata() | ||
..isPublic = atKey.metadata.isPublic | ||
..isCached = atKey.metadata.isCached) | ||
..isLocal = atKey.isLocal) | ||
..operation = 'all'; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier, the AtKey.key is a nullable variable, but the named argument "key" does not accept NULL value. Hence defaulted to empty string in case of null. In at_commons-4.0.0, the AtKey.key is prefixed with late and "?" (which denotes that variable can be null) is removed because key can never be null in AtKey,