Skip to content

Conversation

dani-garcia
Copy link
Member

@dani-garcia dani-garcia commented Oct 1, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-22591

📔 Objective

Currently, all app crates (wasm, uniffi) need to declare all the client managed repositories that they allow clients to implement. This means that all the crates need to be updated when adding more repositories, which adds more steps to implementations and can lead to things being out of sync. This PR unifies the declaration of client managed repositories so that there's only one place where they are defined.

While I was at it, I've changed slightly the way we register the repositories. Rather than provide one function for each (register_cipher_repository/register_folder_repository) I provide a single function that takes an object that contains all the repos. This is easier to generate and should make it easier to know if any of the repos are missing (you should get a compile error). I left the previous ones for backwards-compat

Sadly both wasm and uniffi have a lot of compile time type shenanigans and macros which don't make this easy, so this solution contains multiple parts:

  • In bitwarden_wasm and bitwarden_uniffi we already have a macro that creates the repository implementations based on a type. This has been expanded to take multiple types and also create the Repositories struct which is just a grouping of all of them. Now, instead of manually calling these macros manually for each type, they instead get passed to the bitwarden_pm::create_client_managed_repositories! macro.
  • The bitwarden_pm::create_client_managed_repositories! macro's only purpose is to call the passed macro repeatedly with all the types that need to be created. This is the only way I found to lazily define the types in bitwarden-pm so that they would be usable in macros in the other crates. The definition is fairly repetitive with the types, because we don't have easy ways to change the case of identifiers or merge them together. We could use the paste crate to avoid the repetition but didn't seem worth it at the moment

Note that in the past we placed the sdk-managed definitions in a shared bitwarden-state-migrations crate, but now that we have the new bitwarden-pm crate as a shared crate focused on password manager functionality I don't think bitwarden-state-migrations is needed. Instead this PR moves the sdk-managed definitions to bitwarden-pm (next to the new client managed repositories macro) and deletes the bitwarden-state-migrations crate.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Oct 1, 2025

Logo
Checkmarx One – Scan Summary & Details0e7a6023-56e8-4ea7-83d7-58d93106ad1e

Great job! No new security vulnerabilities introduced in this pull request

Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 0% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.98%. Comparing base (a92fff9) to head (0226999).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...bitwarden-wasm-internal/src/platform/repository.rs 0.00% 33 Missing ⚠️
crates/bitwarden-uniffi/src/platform/repository.rs 0.00% 28 Missing ⚠️
crates/bitwarden-pm/src/migrations.rs 0.00% 8 Missing ⚠️
crates/bitwarden-uniffi/src/platform/mod.rs 0.00% 4 Missing ⚠️
crates/bitwarden-wasm-internal/src/platform/mod.rs 0.00% 4 Missing ⚠️
crates/bitwarden-pm/src/lib.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
- Coverage   78.04%   77.98%   -0.06%     
==========================================
  Files         287      287              
  Lines       27651    27672      +21     
==========================================
  Hits        21579    21579              
- Misses       6072     6093      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dani-garcia dani-garcia marked this pull request as ready for review October 2, 2025 12:58
@dani-garcia dani-garcia requested a review from a team as a code owner October 2, 2025 12:58
@dani-garcia dani-garcia requested a review from coroiu October 2, 2025 12:58
Comment on lines +45 to +55
```rust
macro_rules! create_client_managed_repositories {
($container_name:ident, $macro:ident) => {
$macro! {
$container_name;
// List any SDK-managed repositories here. The format is:
// <fully qualified path to the item>, <item type idenfier>, <field name>, <name of the repository implementation>
::bitwarden_vault::Cipher, Cipher, cipher, CipherRepository;
::bitwarden_vault::Folder, Folder, folder, FolderRepository;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Nice idea! Using macros do define the repositories in a place where we're not actually able to depend on them 👍

Copy link

sonarqubecloud bot commented Oct 8, 2025

@dani-garcia dani-garcia merged commit 7963cdc into main Oct 8, 2025
52 checks passed
@dani-garcia dani-garcia deleted the ps/PM-22591-unify-repository-init branch October 8, 2025 10:18
bw-ghapp bot pushed a commit to bitwarden/sdk-swift that referenced this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants