From 74f2a13fd3db355e95816b74bd5960e9b7e9136c Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Tue, 23 Jan 2024 18:03:29 +0100 Subject: [PATCH 1/2] [bindgen] util::Optional is preferred over std::optional --- bindgen/spec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/spec.yml b/bindgen/spec.yml index 406bc90cf4d..6a5a3687a04 100644 --- a/bindgen/spec.yml +++ b/bindgen/spec.yml @@ -1207,7 +1207,7 @@ classes: unsubscribe: '(token: AppSubscriptionToken)' call_function: '(user: const SharedSyncUser&, name: std::string, args: EJsonArray, service_name: util::Optional, cb: AsyncCallback<(result: Nullable, err: util::Optional)>)' make_streaming_request: '(user: SharedSyncUser, name: std::string, args: bson::BsonArray, service_name: util::Optional) -> Request' - update_base_url: '(base_url: std::optional, cb: AsyncCallback<(err: util::Optional)>&&)' + update_base_url: '(base_url: util::Optional, cb: AsyncCallback<(err: util::Optional)>&&)' get_base_url: '() const -> std::string' WatchStream: From fc07fa8c3a9fddb82c990eb657bb4dec6a8bdfc6 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Tue, 30 Jan 2024 14:04:16 +0100 Subject: [PATCH 2/2] Use std::optional only --- bindgen/spec.yml | 158 ++++++++++++++++++------------------ bindgen/src/bound-model.ts | 4 +- bindgen/src/realm_helpers.h | 1 + 3 files changed, 82 insertions(+), 81 deletions(-) diff --git a/bindgen/spec.yml b/bindgen/spec.yml index 6a5a3687a04..8fd2788bbca 100644 --- a/bindgen/spec.yml +++ b/bindgen/spec.yml @@ -70,7 +70,7 @@ typeAliases: ErrorCodes::Error: int32_t templates: # value tells you how many arguments it takes ('*' means any number) - util::Optional: 1 + std::optional: 1 std::vector: 1 std::shared_ptr: 1 std::pair: 2 @@ -180,7 +180,7 @@ enums: cppName: ClientResyncMode values: - Manual - - DiscardLocal + - DiscardLocal - Recover - RecoverOrDiscard @@ -375,7 +375,7 @@ records: fields: longitude: double latitude: double - altitude: + altitude: type: double default: std::numeric_limits::quiet_NaN() @@ -392,7 +392,7 @@ records: GeoPolygon: fields: points: std::vector> - + RealmConfig: fields: path: std::string @@ -409,7 +409,7 @@ records: in_memory: type: bool default: false - schema: util::Optional> + schema: std::optional> schema_version: type: SchemaVersion default: -1 @@ -447,7 +447,7 @@ records: id: type: ObjectId key: - type: util::Optional + type: std::optional name: type: std::string disabled: @@ -473,31 +473,31 @@ records: type: bool default: false error_handler: 'Nullable void>>' - custom_http_headers: + custom_http_headers: type: 'std::map' default: {} client_validate_ssl: type: bool default: true - ssl_trust_certificate_path: util::Optional + ssl_trust_certificate_path: std::optional ssl_verify_callback: Nullable client_resync_mode: - type: ClientResetMode + type: ClientResetMode default: ClientResyncMode::Manual; notify_before_client_reset: 'Nullable void>>' notify_after_client_reset: 'Nullable void>>' cancel_waits_on_nonfatal_error: type: bool default: false - proxy_config: util::Optional - + proxy_config: std::optional + SyncSubscription: cppName: sync::Subscription fields: id: ObjectId created_at: Timestamp updated_at: Timestamp - name: util::Optional + name: std::optional object_class_name: std::string query_string: std::string @@ -561,7 +561,7 @@ records: metadata_mode: type: MetadataMode default: MetadataMode::Encryption - custom_encryption_key: util::Optional + custom_encryption_key: std::optional logger_factory: Nullable log_level: type: LoggerLevel @@ -636,8 +636,8 @@ records: fields: app_id: std::string transport: SharedGenericNetworkTransport - base_url: util::Optional - default_request_timeout_ms: util::Optional + base_url: std::optional + default_request_timeout_ms: std::optional device_info: DeviceInfo CompensatingWriteErrorInfo: @@ -849,13 +849,13 @@ classes: limit: '(max_count: count_t) const -> Results' snapshot: '() const -> Results' freeze: '(frozen_realm: SharedRealm) const -> Results' - max: '(column: ColKey) -> util::Optional' - min: '(column: ColKey) -> util::Optional' - average: '(column: ColKey) -> util::Optional' - sum: '(column: ColKey) -> util::Optional' + max: '(column: ColKey) -> std::optional' + min: '(column: ColKey) -> std::optional' + average: '(column: ColKey) -> std::optional' + sum: '(column: ColKey) -> std::optional' clear: () - add_notification_callback: '(cb: (changes: const CollectionChangeSet&), keyPaths: util::Optional) -> NotificationToken' + add_notification_callback: '(cb: (changes: const CollectionChangeSet&), keyPaths: std::optional) -> NotificationToken' Realm: sharedPtrWrapped: SharedRealm @@ -869,7 +869,7 @@ classes: # - suffix: from_reference_with_sched # sig: '(thread: ThreadSafeReference, scheduler: SharedScheduler) -> SharedRealm' get_synchronized_realm: '(config: RealmConfig) -> SharedAsyncOpenTask' - #make_shared_realm: '(config: Realm::Config, version: util::Optional, coordinator: std::shared_ptr<_impl::RealmCoordinator>) -> SharedRealm' + #make_shared_realm: '(config: Realm::Config, version: std::optional, coordinator: std::shared_ptr<_impl::RealmCoordinator>) -> SharedRealm' get_schema_version: '(config: const RealmConfig&) const -> SchemaVersion' properties: @@ -883,7 +883,7 @@ classes: get_number_of_versions: uint64_t read_transaction_version: VersionID - current_transaction_version: util::Optional + current_transaction_version: std::optional auto_refresh: bool @@ -926,7 +926,7 @@ classes: - () const - suffix: maybe_throw sig: '(throw_on_error: bool) const' - + create_key_path_array: '(table_name: StringData, key_paths: const std::vector&) -> KeyPathArray' close: () @@ -943,7 +943,7 @@ classes: constructors: make: '(realm: SharedRealm, obj: Obj)' methods: - add_callback: '(cb: (changes: ObjectChangeSet), keyPaths: util::Optional) -> uint64_t' + add_callback: '(cb: (changes: ObjectChangeSet), keyPaths: std::optional) -> uint64_t' remove_callback: '(token: uint64_t)' NotificationToken: @@ -989,7 +989,7 @@ classes: - '(order: SortDescriptor) const -> Results' - sig: '(keyPaths: std::vector> const&) const -> Results' suffix: 'by_name' - add_notification_callback: '(cb: (changes: const CollectionChangeSet&), keyPaths: util::Optional) -> NotificationToken' + add_notification_callback: '(cb: (changes: const CollectionChangeSet&), keyPaths: std::optional) -> NotificationToken' List: base: Collection @@ -1011,16 +1011,16 @@ classes: freeze: '(frozen_realm: SharedRealm const&) const -> List' max: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of min: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of average: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of sum: - '() const -> Mixed' @@ -1053,16 +1053,16 @@ classes: # assign_symmetric_difference: '(rhs: const Collection&) -> void' max: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of min: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of average: - - '() const -> util::Optional' - - sig: '(column: ColKey) const -> util::Optional' + - '() const -> std::optional' + - sig: '(column: ColKey) const -> std::optional' suffix: of sum: - '() const -> Mixed' @@ -1085,10 +1085,10 @@ classes: get_pair: '(ndx: count_t) const -> std::pair' contains: '(key: StringData) -> bool' freeze: '(frozen_realm: SharedRealm const&) const -> Dictionary' - add_key_based_notification_callback: '(cb: (changes: DictionaryChangeSet), keyPaths: util::Optional) -> NotificationToken' + add_key_based_notification_callback: '(cb: (changes: DictionaryChangeSet), keyPaths: std::optional) -> NotificationToken' insert_any: '(key: StringData, value: Mixed) -> std::pair' insert_embedded: '(key: StringData) -> Obj' - try_get_any: '(key: StringData) const -> util::Optional' + try_get_any: '(key: StringData) const -> std::optional' remove_all: '()' try_erase: '(key: StringData) -> bool' @@ -1140,9 +1140,9 @@ classes: refresh_token: std::string device_id: std::string has_device_id: bool - user_profile: UserProfile + user_profile: UserProfile identities: std::vector - custom_data: util::Optional + custom_data: std::optional sync_manager: SharedSyncManager state: SyncUserState subscribers_count: count_t @@ -1156,16 +1156,16 @@ classes: UserProfile: cppName: SyncUserProfile methods: - name: '() -> util::Optional' - email: '() -> util::Optional' - picture_url: '() -> util::Optional' - first_name: '() -> util::Optional' - last_name: '() -> util::Optional' - gender: '() -> util::Optional' - birthday: '() -> util::Optional' - min_age: '() -> util::Optional' - max_age: '() -> util::Optional' - data: '() -> bson::BsonDocument' + name: '() -> std::optional' + email: '() -> std::optional' + picture_url: '() -> std::optional' + first_name: '() -> std::optional' + last_name: '() -> std::optional' + gender: '() -> std::optional' + birthday: '() -> std::optional' + min_age: '() -> std::optional' + max_age: '() -> std::optional' + data: '() -> bson::BsonDocument' AppSubscriptionToken: cppName: app::App::Token @@ -1186,16 +1186,16 @@ classes: close_all_sync_sessions: () methods: - log_in_with_credentials: '(credentials: AppCredentials, cb: AsyncCallback<(user: const Nullable&, err: util::Optional)>&&)' + log_in_with_credentials: '(credentials: AppCredentials, cb: AsyncCallback<(user: const Nullable&, err: std::optional)>&&)' log_out: - - '(cb: AsyncCallback<(err: util::Optional)>&&)' - - sig: '(user: SharedSyncUser, cb: AsyncCallback<(err: util::Optional)>&&)' + - '(cb: AsyncCallback<(err: std::optional)>&&)' + - sig: '(user: SharedSyncUser, cb: AsyncCallback<(err: std::optional)>&&)' suffix: user - refresh_custom_data: '(user: SharedSyncUser, cb: AsyncCallback<(err: util::Optional)>&&)' - link_user: '(user: SharedSyncUser, credentials: const AppCredentials&, cb: AsyncCallback<(user: const Nullable&, err: util::Optional)>&&)' + refresh_custom_data: '(user: SharedSyncUser, cb: AsyncCallback<(err: std::optional)>&&)' + link_user: '(user: SharedSyncUser, credentials: const AppCredentials&, cb: AsyncCallback<(user: const Nullable&, err: std::optional)>&&)' switch_user: '(user: SharedSyncUser)' - remove_user: '(user: SharedSyncUser, cb: AsyncCallback<(err: util::Optional)>&&)' - delete_user: '(user: SharedSyncUser, cb: AsyncCallback<(err: util::Optional)>&&)' + remove_user: '(user: SharedSyncUser, cb: AsyncCallback<(err: std::optional)>&&)' + delete_user: '(user: SharedSyncUser, cb: AsyncCallback<(err: std::optional)>&&)' usernamePasswordProviderClient: - sig: () -> UsernamePasswordProviderClient cppName: provider_client @@ -1205,9 +1205,9 @@ classes: push_notification_client: '(service_name: const std::string&) -> PushClient' subscribe: '(observer: (app: IgnoreArgument)) -> AppSubscriptionToken' unsubscribe: '(token: AppSubscriptionToken)' - call_function: '(user: const SharedSyncUser&, name: std::string, args: EJsonArray, service_name: util::Optional, cb: AsyncCallback<(result: Nullable, err: util::Optional)>)' - make_streaming_request: '(user: SharedSyncUser, name: std::string, args: bson::BsonArray, service_name: util::Optional) -> Request' - update_base_url: '(base_url: util::Optional, cb: AsyncCallback<(err: util::Optional)>&&)' + call_function: '(user: const SharedSyncUser&, name: std::string, args: EJsonArray, service_name: std::optional, cb: AsyncCallback<(result: Nullable, err: std::optional)>)' + make_streaming_request: '(user: SharedSyncUser, name: std::string, args: bson::BsonArray, service_name: std::optional) -> Request' + update_base_url: '(base_url: std::optional, cb: AsyncCallback<(err: std::optional)>&&)' get_base_url: '() const -> std::string' WatchStream: @@ -1223,29 +1223,29 @@ classes: PushClient: cppName: app::PushClient methods: - register_device: '(registration_token: const std::string&, sync_user: const SharedSyncUser&, completion: AsyncCallback<(err: util::Optional)>&&)' - deregister_device: '(sync_user: const SharedSyncUser&, completion: AsyncCallback<(err: util::Optional)>&&)' + register_device: '(registration_token: const std::string&, sync_user: const SharedSyncUser&, completion: AsyncCallback<(err: std::optional)>&&)' + deregister_device: '(sync_user: const SharedSyncUser&, completion: AsyncCallback<(err: std::optional)>&&)' UsernamePasswordProviderClient: cppName: app::App::UsernamePasswordProviderClient methods: - register_email: '(email: const std::string&, password: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - retry_custom_confirmation: '(email: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - confirm_user: '(token: const std::string&, token_id: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - resend_confirmation_email: '(email: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - reset_password: '(password: const std::string&, token: const std::string&, token_id: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - send_reset_password_email: '(email: const std::string&, completion: AsyncCallback<(err: util::Optional)>&&)' - call_reset_password_function: '(email: const std::string&, password: const std::string&, args: const bson::BsonArray&, completion: AsyncCallback<(err: util::Optional)>&&)' + register_email: '(email: const std::string&, password: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + retry_custom_confirmation: '(email: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + confirm_user: '(token: const std::string&, token_id: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + resend_confirmation_email: '(email: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + reset_password: '(password: const std::string&, token: const std::string&, token_id: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + send_reset_password_email: '(email: const std::string&, completion: AsyncCallback<(err: std::optional)>&&)' + call_reset_password_function: '(email: const std::string&, password: const std::string&, args: const bson::BsonArray&, completion: AsyncCallback<(err: std::optional)>&&)' UserAPIKeyProviderClient: cppName: app::App::UserAPIKeyProviderClient methods: - create_api_key: '(name: const std::string&, user: SharedSyncUser, completion: AsyncCallback<(apiKey: UserAPIKey&&, err: util::Optional)>&&)' - fetch_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(apiKey: UserAPIKey&&, err: util::Optional)>&&)' - fetch_api_keys: '(user: const SharedSyncUser, completion: AsyncCallback<(apiKeys: std::vector&&, err: util::Optional)>&&)' - delete_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: util::Optional)>&&)' - enable_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: util::Optional)>&&)' - disable_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: util::Optional)>&&)' + create_api_key: '(name: const std::string&, user: SharedSyncUser, completion: AsyncCallback<(apiKey: UserAPIKey&&, err: std::optional)>&&)' + fetch_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(apiKey: UserAPIKey&&, err: std::optional)>&&)' + fetch_api_keys: '(user: const SharedSyncUser, completion: AsyncCallback<(apiKeys: std::vector&&, err: std::optional)>&&)' + delete_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: std::optional)>&&)' + enable_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: std::optional)>&&)' + disable_api_key: '(id: ObjectId&, user: const SharedSyncUser, completion: AsyncCallback<(err: std::optional)>&&)' # See Helpers::make_loger_factory to construct one. # Using an opaque class here rather than exposing the factory to avoid having to @@ -1270,7 +1270,7 @@ classes: set_timeouts: '(timeouts: SyncClientTimeouts)' reconnect: () wait_for_sessions_to_terminate: () - path_for_realm: '(config: SyncConfig, custom_file_name: util::Optional) -> StringData' + path_for_realm: '(config: SyncConfig, custom_file_name: std::optional) -> StringData' get_existing_active_session: '(path: const std::string&) -> SharedSyncSession' ThreadSafeReference: {} @@ -1290,7 +1290,7 @@ classes: path: std::string user: SharedSyncUser config: SyncConfig - full_realm_url: util::Optional + full_realm_url: std::optional methods: wait_for_upload_completion: '(callback: AsyncCallback<(err: Status) off_thread>)' wait_for_download_completion: '(callback: AsyncCallback<(err: Status) off_thread>)' @@ -1319,7 +1319,7 @@ classes: size: count_t methods: make_mutable_copy: () const -> MutableSyncSubscriptionSet - get_state_change_notification: '(notify_when: SyncSubscriptionSetState, callback: AsyncCallback<(new_state: util::Optional, err: util::Optional) off_thread>) const' + get_state_change_notification: '(notify_when: SyncSubscriptionSetState, callback: AsyncCallback<(new_state: std::optional, err: std::optional) off_thread>) const' at: '(index: count_t) const -> const SyncSubscription&' find: - sig: '(name: StringData) const -> Nullable' diff --git a/bindgen/src/bound-model.ts b/bindgen/src/bound-model.ts index c61ed8f7857..987d2ae47a5 100644 --- a/bindgen/src/bound-model.ts +++ b/bindgen/src/bound-model.ts @@ -32,10 +32,10 @@ abstract class TypeBase { return this.kind === kind; } - isOptional(): this is Template & { name: "util::Optional" }; + isOptional(): this is Template & { name: "std::optional" }; isOptional(type: string): boolean; isOptional(type?: string): boolean { - return this.isTemplate("util::Optional") && (!type || ("name" in this.args[0] && this.args[0].name === type)); + return this.isTemplate("std::optional") && (!type || ("name" in this.args[0] && this.args[0].name === type)); } isNullable(): this is Template & { name: "Nullable" }; diff --git a/bindgen/src/realm_helpers.h b/bindgen/src/realm_helpers.h index 2ac02b8cd10..469301846d7 100644 --- a/bindgen/src/realm_helpers.h +++ b/bindgen/src/realm_helpers.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include