Skip to content

added handling replicator listeners #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Wojtach
Copy link

@Wojtach Wojtach commented Apr 29, 2025

Removed DataAdapter.kt as it was used only for replicator and not working. I created ReplicatorHelper.kt to be consistent with cbl-js-ios submodule

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @Wojtach, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on adding functionality to handle replicator listeners in a Couchbase Lite environment, likely within a React Native context. It introduces a new ReplicatorHelper object with functions for creating replicator configurations from JSON, processing collection configurations, creating authenticators, and generating map representations of replicator status and document replication data. It also includes a minor fix in DatabaseManager.kt to use the correct variable name when storing open databases.

Highlights

  • Replicator Configuration: The ReplicatorHelper provides a function replicatorConfigFromJson to create a ReplicatorConfiguration object from a ReadableMap, handling various properties like target URL, replicator type, continuous mode, headers, and authentication.
  • Collection Configuration: The ReplicatorHelper includes a function processCollectionConfig to handle collection-specific configurations, including channels and document IDs, by parsing a JSON string.
  • Authenticator Creation: The ReplicatorHelper provides a function createAuthenticator to create BasicAuthenticator or SessionAuthenticator objects based on the configuration provided in a ReadableMap.
  • Status and Document Replication Data: The ReplicatorHelper includes functions generateReplicatorStatusMap and generateDocumentReplicationMap to generate WritableMap representations of replicator status and document replication data, respectively, for use in React Native.

Changelog

  • DatabaseManager.kt
    • Corrected the variable name used when storing open databases from uniqueName to databaseUniqueName.
  • ReplicatorHelper.kt
    • Introduced the ReplicatorHelper object with functions for creating replicator configurations from JSON.
    • Added functions for processing collection configurations, including channels and document IDs.
    • Implemented functions for creating authenticators (Basic and Session).
    • Added functions for generating map representations of replicator status and document replication data.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A replicator's task,
Syncing data, no easy ask,
JSON configs flow,
Data starts to grow,
Listeners watch, behind the mask.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new ReplicatorHelper class to handle replicator configurations and status, as well as modifies DatabaseManager to use the correct database unique name. The new functionality seems well-structured, but there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Error Handling in replicatorConfigFromJson: The replicatorConfigFromJson function catches exceptions and logs them, but then re-throws the exception. This pattern can make debugging harder, as the original stack trace is lost. Consider wrapping the exception with a more specific exception type or providing more context in the log message.
  • Redundant Null Checks: There are several places where null checks are performed on values obtained from ReadableMap (e.g., collectionConfigStr.isNullOrEmpty()). Kotlin's type system and the use of ?: operator can often simplify these checks.
  • Inconsistent use of Log.d vs Log.e: The code uses Log.d for some error conditions and Log.e for others. It would be good to use Log.e for actual errors and Log.d for debugging information.

Merge Readiness

The pull request introduces significant new functionality. While the code appears functional, addressing the error handling and null check concerns would improve the robustness and maintainability of the code. I recommend addressing the identified issues before merging. I am unable to directly approve the pull request, and other reviewers should review and approve this code before merging.

Copy link
Contributor

@azaddhirajkumar azaddhirajkumar left a comment

Choose a reason for hiding this comment

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

You have mentioned about DataAdapter file here, but I don't see any changes related to that file here.

Also, please update the PR description with more details about this PR and how it affects cbl-reactnative.

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