Skip to content

Commit

Permalink
Upgrade to Core 14.7.0 (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire authored May 24, 2024
1 parent 322abf8 commit a7a5b4c
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ jobs:
with:
submodules: 'recursive'

- name: Select Python 3.10
if: matrix.os == 'macos-latest'
# otherwise turtlebrowser/[email protected] fails on macos-12
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
X.Y.Z Release notes (YYYY-MM-DD)
=============================================================

### Fixed
* None

### Enhancements
* None

### Breaking changes
* `sync_manager::path_for_realm(const realm::sync_config&)` is now `App::path_for_realm(const realm::sync_config&)`

### Compatibility
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10.

### Internals
* Upgraded to Core v14.7.0

----------------------------------------------

1.1.1 Release notes (2024-04-17)
=============================================================

Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PackageDescription

let sdkVersion = Version("1.1.1")
let coreVersion = Version("14.5.1")
let coreVersion = Version("14.7.0")

var cxxSettings: [CXXSetting] = [
.define("REALM_ENABLE_SYNC", to: "1"),
Expand Down Expand Up @@ -68,13 +68,13 @@ let package = Package(
targets: ["realm-cpp-sdk"]),
],
dependencies: [
.package(url: "https://github.com/realm/realm-core.git", revision: "316889b967f845fbc10b4422f96c7eadd47136f2")
.package(url: "https://github.com/realm/realm-core.git", exact: coreVersion)
],
targets: [
cppSdkTarget,
.target(
name: "Catch2Generated",
path: "realm-core/external/generated",
path: "tests/external/generated",
// this file was manually generated with catch v3.0.1
// and should be regenerated when catch is upgraded
resources: [.copy("catch2/catch_user_config.hpp")],
Expand Down
23 changes: 7 additions & 16 deletions include/cpprealm/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
namespace realm {
using proxy_config = sync_config::proxy_config;
using sync_session = internal::bridge::sync_session;
class SyncUser;

namespace app {
class App;
class User;
struct AppError;
}// namespace app
namespace internal::bridge {
Expand Down Expand Up @@ -92,7 +92,7 @@ struct user {
user(user&&) = default;
user& operator=(const user&) = default;
user& operator=(user&&) = default;
explicit user(std::shared_ptr<SyncUser> user);
explicit user(std::shared_ptr<app::User> user);
bool is_logged_in() const;

/**
Expand Down Expand Up @@ -133,18 +133,7 @@ struct user {

struct internal::bridge::sync_manager sync_manager() const;

[[nodiscard]] db_config flexible_sync_configuration() const
{
db_config config;
config.set_sync_config(sync_config(m_user));
config.sync_config().set_error_handler([](const sync_session&, const internal::bridge::sync_error& error) {
std::cerr<<"ADS C++ SDK: Sync Error: " << error.message() << "\n";
});
config.set_path(sync_manager().path_for_realm(config.sync_config()));
config.sync_config().set_stop_policy(realm::internal::bridge::realm::sync_session_stop_policy::after_changes_uploaded);
config.set_schema_mode(realm::internal::bridge::realm::config::schema_mode::additive_discovered);
return config;
}
[[nodiscard]] db_config flexible_sync_configuration() const;

/**
Logs out the current user
Expand Down Expand Up @@ -221,7 +210,7 @@ struct user {
*/
[[nodiscard]] std::future<void> refresh_custom_user_data() const;

std::shared_ptr<SyncUser> m_user;
std::shared_ptr<app::User> m_user;
};

bool operator==(const user& lhs, const user& rhs);
Expand Down Expand Up @@ -296,8 +285,10 @@ class App {
@return A void future once the operation has completed.
This handler is executed on the thread the method was called from.
*/
[[nodiscard]] std::future<void> update_base_url(std::optional<std::string> base_url) const;
[[nodiscard]] std::future<void> update_base_url(std::string base_url) const;
#endif

[[nodiscard]] std::string path_for_realm(const realm::sync_config&) const;
private:
std::shared_ptr<app::App> m_app;
App(std::shared_ptr<app::App>&& a) : m_app(std::move(a)) { }
Expand Down
1 change: 1 addition & 0 deletions include/cpprealm/internal/bridge/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ namespace realm::internal::bridge {
#endif
};
struct collection_change_callback {
virtual ~collection_change_callback() {}
virtual void before(collection_change_set const& c) = 0;
virtual void after(collection_change_set const& c) = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions include/cpprealm/internal/bridge/realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace realm {
struct SyncConfig;
struct scheduler;
class SyncUser;
namespace app {
class User;
}

enum class client_reset_mode: uint8_t {
// Fire a client reset error
Expand Down
1 change: 0 additions & 1 deletion include/cpprealm/internal/bridge/sync_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace realm {

namespace internal::bridge {
struct sync_manager {
[[nodiscard]] std::string path_for_realm(const realm::sync_config&) const;
void set_log_level(logger::level);
private:
friend class ::realm::App;
Expand Down
2 changes: 1 addition & 1 deletion include/cpprealm/observation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace realm {
: block(std::move(b)), object(*obj), m_object(internal_object) {
static_cast<void>(obj);
}
std::function<void(object_change < T > )> block;
std::function<void(object_change<T>)> block;
const T object;
std::shared_ptr<internal::bridge::object> m_object;

Expand Down
2 changes: 1 addition & 1 deletion realm-core
Submodule realm-core updated 330 files
71 changes: 47 additions & 24 deletions src/cpprealm/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#endif

#include <realm/object-store/sync/app.hpp>
#include <realm/object-store/sync/app_user.hpp>
#include <realm/object-store/sync/sync_manager.hpp>
#include <realm/object-store/sync/sync_user.hpp>
#include <realm/sync/config.hpp>
#include <realm/util/bson/bson.hpp>

#include <utility>
Expand Down Expand Up @@ -156,7 +158,7 @@ namespace realm {
#endif
}

user::user(std::shared_ptr<SyncUser> user) : m_user(std::move(user))
user::user(std::shared_ptr<app::User> user) : m_user(std::move(user))
{
}

Expand All @@ -166,7 +168,7 @@ namespace realm {
*/
[[nodiscard]] std::string user::identifier() const
{
return m_user->identity();
return m_user->user_id();
}

/**
Expand Down Expand Up @@ -208,7 +210,7 @@ namespace realm {
*/
void user::log_out(std::function<void(std::optional<app_error>)>&& callback) const
{
m_user->sync_manager()->app().lock()->log_out(m_user, [cb = std::move(callback)](auto error) {
m_user->app()->log_out(m_user, [cb = std::move(callback)](auto error) {
cb(error ? std::optional<app_error>{app_error(std::move(*error))} : std::nullopt);
});
}
Expand All @@ -217,7 +219,7 @@ namespace realm {
{
std::promise<void> p;
std::future<void> f = p.get_future();
m_user->sync_manager()->app().lock()->log_out(m_user, [p = std::move(p)](auto err) mutable {
m_user->app()->log_out(m_user, [p = std::move(p)](auto err) mutable {
if (err) {
p.set_exception(std::make_exception_ptr(app_error(std::move(*err))));
} else {
Expand All @@ -227,6 +229,19 @@ namespace realm {
return f;
}

db_config user::flexible_sync_configuration() const
{
db_config config;
config.set_sync_config(sync_config(m_user));
config.sync_config().set_error_handler([](const sync_session&, const internal::bridge::sync_error& error) {
std::cerr << "ADS C++ SDK: Sync Error: " << error.message() << "\n";
});
config.set_path(m_user->app()->path_for_realm(*config.sync_config().operator std::shared_ptr<SyncConfig>()));
config.sync_config().set_stop_policy(realm::internal::bridge::realm::sync_session_stop_policy::after_changes_uploaded);
config.set_schema_mode(realm::internal::bridge::realm::config::schema_mode::additive_discovered);
return config;
}

std::optional<std::string> user::custom_data() const
{
if (auto v = m_user->custom_data()) {
Expand All @@ -248,7 +263,7 @@ namespace realm {
void user::call_function(const std::string& name, const std::string& arguments,
std::function<void(std::optional<std::string>, std::optional<app_error>)> callback) const
{
m_user->sync_manager()->app().lock()->call_function(m_user, name, arguments, std::nullopt, [cb = std::move(callback)](const std::string* bson_string,
m_user->app()->call_function(m_user, name, arguments, std::nullopt, [cb = std::move(callback)](const std::string* bson_string,
std::optional<app_error> err) {
cb(bson_string ? std::optional<std::string>(*bson_string) : std::nullopt, err);
});
Expand All @@ -259,7 +274,7 @@ namespace realm {
std::promise<std::optional<std::string>> p;
std::future<std::optional<std::string>> f = p.get_future();

m_user->sync_manager()->app().lock()->call_function(m_user, name, arguments, std::nullopt, [p = std::move(p)](const std::string* bson_string,
m_user->app()->call_function(m_user, name, arguments, std::nullopt, [p = std::move(p)](const std::string* bson_string,
std::optional<app_error> err) mutable {
if (err) {
p.set_exception(std::make_exception_ptr(app_error(std::move(*err))));
Expand All @@ -277,7 +292,7 @@ namespace realm {
for(auto& b : args_bson) {
core_bson.push_back(b);
}
m_user->sync_manager()->app().lock()->call_function(m_user, name, core_bson, std::nullopt, [cb = std::move(callback)](util::Optional<bson::Bson>&& b,
m_user->app()->call_function(m_user, name, core_bson, std::nullopt, [cb = std::move(callback)](util::Optional<bson::Bson>&& b,
std::optional<app_error> err) {
cb(b ? std::optional<bsoncxx>(*b) : std::nullopt, err);
});
Expand All @@ -292,7 +307,7 @@ namespace realm {
core_bson.push_back(b);
}

m_user->sync_manager()->app().lock()->call_function(m_user, name, core_bson, std::nullopt, [p = std::move(p)](util::Optional<bson::Bson>&& b,
m_user->app()->call_function(m_user, name, core_bson, std::nullopt, [p = std::move(p)](util::Optional<bson::Bson>&& b,
std::optional<app_error> err) mutable {
if (err) {
p.set_exception(std::make_exception_ptr(app_error(std::move(*err))));
Expand Down Expand Up @@ -326,7 +341,7 @@ namespace realm {
}

internal::bridge::sync_manager user::sync_manager() const {
return m_user->sync_manager();
return std::shared_ptr<SyncManager>(m_user->sync_manager());
}

bool user::is_logged_in() const {
Expand Down Expand Up @@ -457,6 +472,8 @@ namespace realm {
#if QT_CORE_LIB
util::Scheduler::set_default_factory(util::make_qt);
#endif
auto app_config = app::AppConfig();

SyncClientConfig client_config;
client_config.logger_factory = ([](::realm::util::Logger::Level level) {
auto logger = std::make_unique<::realm::util::ThreadSafeLogger>(std::make_shared<DefaultSyncLogger>());
Expand All @@ -470,43 +487,45 @@ namespace realm {
#else
bool should_encrypt = config.metadata_encryption_key && !getenv("REALM_DISABLE_METADATA_ENCRYPTION");
#endif
client_config.metadata_mode = should_encrypt ? SyncManager::MetadataMode::Encryption : SyncManager::MetadataMode::NoEncryption;
if (config.metadata_encryption_key) {
auto key = std::vector<char>();
key.resize(64);
key.assign(config.metadata_encryption_key->begin(), config.metadata_encryption_key->end());
client_config.custom_encryption_key = std::move(key);
}

#ifdef QT_CORE_LIB
auto qt_path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString();
if (!std::filesystem::exists(qt_path)) {
std::filesystem::create_directory(qt_path);
}
config.base_file_path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString();
app_config.base_file_path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString();
#else
if (config.path) {
client_config.base_file_path = *config.path;
app_config.base_file_path = *config.path;
} else {
client_config.base_file_path = std::filesystem::current_path().make_preferred().generic_string();
app_config.base_file_path = std::filesystem::current_path().make_preferred().generic_string();
}
#endif
client_config.user_agent_binding_info = std::string("RealmCpp/") + std::string(REALMCXX_VERSION_STRING);
client_config.user_agent_application_info = config.app_id;

auto app_config = app::App::Config();
app_config.app_id = config.app_id;
app_config.transport = std::make_shared<internal::CoreTransport>(config.custom_http_headers, config.proxy_configuration);
app_config.base_url = config.base_url;
auto device_info = app::App::Config::DeviceInfo();

app_config.metadata_mode = should_encrypt ? app::AppConfig::MetadataMode::Encryption : app::AppConfig::MetadataMode::NoEncryption;
if (config.metadata_encryption_key) {
auto key = std::vector<char>();
key.resize(64);
key.assign(config.metadata_encryption_key->begin(), config.metadata_encryption_key->end());
app_config.custom_encryption_key = std::move(key);
}

auto device_info = app::AppConfig::DeviceInfo();

device_info.framework_name = "Realm Cpp",
device_info.platform_version = "?",
device_info.sdk_version = REALMCXX_VERSION_STRING,
device_info.sdk = "Realm Cpp";
app_config.device_info = std::move(device_info);

m_app = app::App::get_app(app::App::CacheMode::Enabled, std::move(app_config), client_config);
app_config.sync_client_config = client_config;
m_app = app::App::get_app(app::App::CacheMode::Enabled, std::move(app_config));
}

App::App(const std::string &app_id,
Expand All @@ -525,6 +544,10 @@ namespace realm {
return m_app->get_base_url();
}

[[nodiscard]] std::string App::path_for_realm(const realm::sync_config& c) const {
return m_app->path_for_realm(*c.operator std::shared_ptr<SyncConfig>());
}

std::future<void> App::register_user(const std::string &username, const std::string &password) {
std::promise<void> p;
std::future<void> f = p.get_future();
Expand Down Expand Up @@ -570,7 +593,7 @@ namespace realm {
}

std::optional<user> App::get_current_user() const {
if (auto u = m_app->sync_manager()->get_current_user()) {
if (auto u = m_app->current_user()) {
return user(u);
}
return std::nullopt;
Expand All @@ -587,7 +610,7 @@ namespace realm {
}

#ifdef REALM_ENABLE_EXPERIMENTAL
[[nodiscard]] std::future<void> App::update_base_url(std::optional<std::string> base_url) const {
[[nodiscard]] std::future<void> App::update_base_url(std::string base_url) const {
std::promise<void> p;
std::future<void> f = p.get_future();
m_app->update_base_url(base_url, ([p = std::move(p)](auto err) mutable {
Expand Down
Loading

0 comments on commit a7a5b4c

Please sign in to comment.