putIfNewer method
Stores secret only if it is newer than any existing (namespace, name)
entry. Returns whether it was stored. This is the conflict rule for
secrets arriving from other clients — and as the arrival/merge path it
accepts reserved (__) names: system secrets must flow between clients.
"Newer" is decided on Secret.version when both carry one (higher wins —
deterministic regardless of any client's clock); otherwise on
Secret.createdAt. A same-version arrival is treated as not-newer (the
existing copy is kept) unless its createdAt is strictly later.
Implementation
Future<bool> putIfNewer(Secret secret) async {
final existing = _secrets[_key(secret.namespace, secret.name)];
if (!_isNewer(secret, existing)) {
return false;
}
await putSecret(secret, allowReservedName: true);
return true;
}