Skip to content

Commit

Permalink
Merge 1212cdb into 82a0b78
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Apr 25, 2024
2 parents 82a0b78 + 1212cdb commit 17c108b
Show file tree
Hide file tree
Showing 53 changed files with 3,967 additions and 3,585 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Expand Up @@ -25,6 +25,7 @@
"geospatial",
"HRESULT",
"keepalive",
"keypaths",
"loggable",
"maccatalyst",
"mugaritz",
Expand Down Expand Up @@ -167,5 +168,7 @@
"__tuple": "cpp",
"__verbose_abort": "cpp"
},
"cmake.sourceDirectory": "${workspaceFolder}/packages/realm_dart"
"cmake.sourceDirectory": "${workspaceFolder}/packages/realm_dart",
"dart.flutterSdkPath": "/Users/kasper/.puro/envs/stable/flutter",
"dart.sdkPath": "/Users/kasper/.puro/envs/stable/flutter/bin/cache/dart-sdk"
}
1 change: 0 additions & 1 deletion analysis_options.yaml
Expand Up @@ -19,7 +19,6 @@ linter:
rules:
avoid_relative_lib_imports: false
package_api_docs: true
dangling_library_doc_comments: false

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
Expand Down
10 changes: 1 addition & 9 deletions packages/realm_common/lib/src/realm_common_base.dart
Expand Up @@ -129,12 +129,4 @@ class Backlink {
/// The name of the field in the other class that links to this class.
final Symbol fieldName;
const Backlink(this.fieldName);
}

/// @nodoc
class Tuple<T1, T2> {
T1 item1;
T2 item2;

Tuple(this.item1, this.item2);
}
}
2 changes: 2 additions & 0 deletions packages/realm_dart/dart_test.yaml
@@ -0,0 +1,2 @@
tags:
baas: { timeout: 2x }
27 changes: 14 additions & 13 deletions packages/realm_dart/lib/src/app.dart
Expand Up @@ -7,11 +7,12 @@ import 'dart:io';
import 'dart:isolate';

import 'package:meta/meta.dart';
import 'package:path/path.dart' as _path;
import 'package:path/path.dart' as path;

import '../realm.dart';
import 'credentials.dart';
import 'logging.dart';
import 'native/app_handle.dart';
import 'native/realm_core.dart';
import 'user.dart';

Expand Down Expand Up @@ -125,7 +126,7 @@ class AppConfiguration {
this.maxConnectionTimeout = const Duration(minutes: 2),
HttpClient? httpClient,
}) : baseUrl = baseUrl ?? Uri.parse(realmCore.getDefaultBaseUrl()),
baseFilePath = baseFilePath ?? Directory(_path.dirname(Configuration.defaultRealmPath)),
baseFilePath = baseFilePath ?? Directory(path.dirname(Configuration.defaultRealmPath)),
httpClient = httpClient ?? _defaultClient {
if (appId == '') {
throw RealmException('Supplied appId must be a non-empty value');
Expand All @@ -144,7 +145,7 @@ class App implements Finalizable {

/// The id of this application. This is the same as the appId in the [AppConfiguration] used to
/// create this [App].
String get id => realmCore.appGetId(this);
String get id => handle.id;

/// Create an app with a particular [AppConfiguration]. This constructor should only be used on the main isolate and,
/// ideally, only once as soon as the app starts.
Expand All @@ -171,18 +172,18 @@ class App implements Finalizable {

static AppHandle _createApp(AppConfiguration configuration) {
configuration.baseFilePath.createSync(recursive: true);
return realmCore.createApp(configuration);
return AppHandle.from(configuration);
}

/// Logs in a user with the given credentials.
Future<User> logIn(Credentials credentials) async {
var userHandle = await realmCore.logIn(this, credentials);
var userHandle = await handle.logIn(credentials.handle);
return UserInternal.create(userHandle, this);
}

/// Gets the currently logged in [User]. If none exists, `null` is returned.
User? get currentUser {
final userHandle = realmCore.getCurrentUser(_handle);
final userHandle = _handle.currentUser;
if (userHandle == null) {
return null;
}
Expand All @@ -191,36 +192,36 @@ class App implements Finalizable {

/// Gets all currently logged in users.
Iterable<User> get users {
return realmCore.getUsers(this).map((handle) => UserInternal.create(handle, this));
return handle.users.map((handle) => UserInternal.create(handle, this));
}

/// Removes a [user] and their local data from the device. If the user is logged in, they will be logged out in the process.
Future<void> removeUser(User user) async {
return await realmCore.removeUser(this, user);
return await handle.removeUser(user.handle);
}

/// Deletes a user and all its data from the device as well as the server.
Future<void> deleteUser(User user) async {
return await realmCore.deleteUser(this, user);
return await handle.deleteUser(user.handle);
}

/// Switches the [currentUser] to the one specified in [user].
void switchUser(User user) {
realmCore.switchUser(this, user);
handle.switchUser(user.handle);
}

/// Provide a hint to this app's sync client to reconnect.
/// Useful when the device has been offline and then receives a network reachability update.
///
/// The sync client will always attempt to reconnect eventually, this is just a hint.
void reconnect() {
realmCore.reconnect(this);
handle.reconnect();
}

/// Returns the current value of the base URL used to communicate with the server.
@experimental
Uri? get baseUrl {
return Uri.tryParse(realmCore.getBaseUrl(this) ?? '');
return Uri.tryParse(handle.baseUrl ?? '');
}

/// Temporarily overrides the [baseUrl] value from [AppConfiguration] with a new [baseUrl] value
Expand All @@ -229,7 +230,7 @@ class App implements Finalizable {
/// The App will revert to using the value in [AppConfiguration] when it is restarted.
@experimental
Future<void> updateBaseUrl(Uri baseUrl) async {
return await realmCore.updateBaseUrl(this, baseUrl);
return await handle.updateBaseUrl(baseUrl);
}

/// Returns an instance of [EmailPasswordAuthProvider]
Expand Down
2 changes: 2 additions & 0 deletions packages/realm_dart/lib/src/cli/common/archive.dart
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

///
library;

import 'dart:io';
import 'package:tar/tar.dart';
import 'package:path/path.dart' as path;
Expand Down
8 changes: 3 additions & 5 deletions packages/realm_dart/lib/src/collections.dart
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:ffi';
import 'native/realm_core.dart';
import 'native/collection_changes_handle.dart';

/// Contains index information about objects that moved within the same collection.
class Move {
Expand Down Expand Up @@ -47,13 +47,11 @@ class MapChanges {

/// Describes the changes in a Realm collection since the last time the notification callback was invoked.
class RealmCollectionChanges implements Finalizable {
final RealmCollectionChangesHandle _handle;
CollectionChanges? _values;
final CollectionChangesHandle _handle;
late final CollectionChanges _changes = _handle.changes;

RealmCollectionChanges(this._handle);

CollectionChanges get _changes => _values ??= realmCore.getCollectionChanges(_handle);

/// The indexes in the previous version of the collection which have been removed from this one.
List<int> get deleted => _changes.deletions;

Expand Down
12 changes: 7 additions & 5 deletions packages/realm_dart/lib/src/configuration.dart
Expand Up @@ -7,10 +7,12 @@ import 'dart:io';

// ignore: no_leading_underscores_for_library_prefixes
import 'package:path/path.dart' as _path;

import 'app.dart';
import 'init.dart';
import 'logging.dart';
import 'native/realm_core.dart';
import 'realm_class.dart';
import 'init.dart';
import 'user.dart';

/// The signature of a callback used to determine if compaction
Expand Down Expand Up @@ -225,8 +227,8 @@ abstract class Configuration implements Finalizable {
return;
}

if (key.length != realmCore.encryptionKeySize) {
throw RealmException("Wrong encryption key size (must be ${realmCore.encryptionKeySize}, but was ${key.length})");
if (key.length != encryptionKeySize) {
throw RealmException("Wrong encryption key size (must be $encryptionKeySize, but was ${key.length})");
}

int notAByteElement = key.firstWhere((e) => e > 255, orElse: () => -1);
Expand Down Expand Up @@ -368,7 +370,7 @@ class FlexibleSyncConfiguration extends Configuration {
}) : super._();

@override
String get _defaultPath => realmCore.getPathForUser(user);
String get _defaultPath => user.handle.path;
}

extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration {
Expand Down Expand Up @@ -653,7 +655,7 @@ class ClientResetError extends SyncError {
throw RealmException("Missing `originalFilePath`");
}
return realmCore.immediatelyRunFileActions(_app!, originalFilePath!);
return _app.handle.immediatelyRunFileActions(originalFilePath!);
}
}
Expand Down
41 changes: 21 additions & 20 deletions packages/realm_dart/lib/src/credentials.dart
Expand Up @@ -4,8 +4,9 @@
import 'dart:convert';
import 'dart:ffi';

import 'native/realm_core.dart';
import 'app.dart';
import 'native/convert.dart';
import 'native/credentials_handle.dart';
import 'user.dart';

/// An enum containing all authentication providers. These have to be enabled manually for the application before they can be used.
Expand Down Expand Up @@ -57,44 +58,44 @@ extension AuthProviderTypeInternal on AuthProviderType {
/// A class, representing the credentials used for authenticating a [User]
/// {@category Application}
class Credentials implements Finalizable {
final RealmAppCredentialsHandle _handle;
final CredentialsHandle _handle;

/// Returns a [Credentials] object that can be used to authenticate an anonymous user.
/// Setting [reuseCredentials] to `false` will create a new anonymous user, upon [App.logIn].
/// [Anonymous Authentication Docs](https://www.mongodb.com/docs/atlas/app-services/authentication/anonymous/#anonymous-authentication)
Credentials.anonymous({bool reuseCredentials = true}) : _handle = realmCore.createAppCredentialsAnonymous(reuseCredentials);
Credentials.anonymous({bool reuseCredentials = true}) : _handle = CredentialsHandle.anonymous(reuseCredentials);

/// Returns a [Credentials] object that can be used to authenticate a user with a Google account using an id token.
Credentials.apple(String idToken) : _handle = realmCore.createAppCredentialsApple(idToken);
Credentials.apple(String idToken) : _handle = CredentialsHandle.apple(idToken);

/// Returns a [Credentials] object that can be used to authenticate a user with their email and password.
/// A user can login with email and password only after they have registered their account and verified their
/// email.
/// [Email/Password Authentication Docs](https://www.mongodb.com/docs/atlas/app-services/authentication/email-password/#email-password-authentication)
Credentials.emailPassword(String email, String password) : _handle = realmCore.createAppCredentialsEmailPassword(email, password);
Credentials.emailPassword(String email, String password) : _handle = CredentialsHandle.emailPassword(email, password);

/// Returns a [Credentials] object that can be used to authenticate a user with a custom JWT.
/// [Custom-JWT Authentication Docs](https://www.mongodb.com/docs/atlas/app-services/authentication/custom-jwt/#custom-jwt-authentication)
Credentials.jwt(String token) : _handle = realmCore.createAppCredentialsJwt(token);
Credentials.jwt(String token) : _handle = CredentialsHandle.jwt(token);

/// Returns a [Credentials] object that can be used to authenticate a user with a Facebook account.
Credentials.facebook(String accessToken) : _handle = realmCore.createAppCredentialsFacebook(accessToken);
Credentials.facebook(String accessToken) : _handle = CredentialsHandle.facebook(accessToken);

/// Returns a [Credentials] object that can be used to authenticate a user with a Google account using an authentication code.
Credentials.googleAuthCode(String authCode) : _handle = realmCore.createAppCredentialsGoogleAuthCode(authCode);
Credentials.googleAuthCode(String authCode) : _handle = CredentialsHandle.googleAuthCode(authCode);

/// Returns a [Credentials] object that can be used to authenticate a user with a Google account using an id token.
Credentials.googleIdToken(String idToken) : _handle = realmCore.createAppCredentialsGoogleIdToken(idToken);
Credentials.googleIdToken(String idToken) : _handle = CredentialsHandle.googleIdToken(idToken);

/// Returns a [Credentials] object that can be used to authenticate a user with a custom Function.
/// [Custom Function Authentication Docs](https://www.mongodb.com/docs/atlas/app-services/authentication/custom-function/)
Credentials.function(String payload) : _handle = realmCore.createAppCredentialsFunction(payload);
Credentials.function(String payload) : _handle = CredentialsHandle.function(payload);

/// Returns a [Credentials] object that can be used to authenticate a user with an API key.
/// To generate an API key, use [ApiKeyClient.create] or the App Services web UI.
Credentials.apiKey(String key) : _handle = realmCore.createAppCredentialsApiKey(key);
Credentials.apiKey(String key) : _handle = CredentialsHandle.apiKey(key);

AuthProviderType get provider => realmCore.userGetCredentialsProviderType(this);
AuthProviderType get provider => handle.providerType;
}

/// @nodoc
Expand All @@ -104,7 +105,7 @@ extension CredentialsInternal on Credentials {
_handle.keepAlive();
}

RealmAppCredentialsHandle get handle => _handle;
CredentialsHandle get handle => _handle;
}

/// A class, encapsulating functionality for users, logged in with [Credentials.emailPassword()].
Expand All @@ -123,38 +124,38 @@ class EmailPasswordAuthProvider implements Finalizable {
///
/// Successful completion indicates that the user has been created on the server and can now be logged in with [Credentials.emailPassword()].
Future<void> registerUser(String email, String password) async {
return realmCore.appEmailPasswordRegisterUser(app, email, password);
return app.handle.registerUser(email, password);
}

/// Confirms a user with the given token and token id. These are typically included in the registration email.
Future<void> confirmUser(String token, String tokenId) {
return realmCore.emailPasswordConfirmUser(app, token, tokenId);
return app.handle.confirmUser(token, tokenId);
}

/// Resend the confirmation email for a user to the given email.
Future<void> resendUserConfirmation(String email) {
return realmCore.emailPasswordResendUserConfirmation(app, email);
return app.handle.resendConfirmation(email);
}

/// Completes the reset password procedure by providing the desired new [password] using the
/// password reset [token] and [tokenId] that were emailed to a user.
Future<void> completeResetPassword(String password, String token, String tokenId) {
return realmCore.emailPasswordCompleteResetPassword(app, password, token, tokenId);
return app.handle.completeResetPassword(password, token, tokenId);
}

/// Sends a password reset email.
Future<void> resetPassword(String email) {
return realmCore.emailPasswordResetPassword(app, email);
return app.handle.requestResetPassword(email);
}

/// Calls the reset password function, configured on the server.
Future<void> callResetPasswordFunction(String email, String password, {List<dynamic>? functionArgs}) {
return realmCore.emailPasswordCallResetPasswordFunction(app, email, password, functionArgs != null ? jsonEncode(functionArgs) : null);
return app.handle.callResetPasswordFunction(email, password, functionArgs.convert(jsonEncode));
}

/// Retries the custom confirmation function on a user for a given email.
Future<void> retryCustomConfirmationFunction(String email) {
return realmCore.emailPasswordRetryCustomConfirmationFunction(app, email);
return app.handle.retryCustomConfirmationFunction(email);
}
}

Expand Down

0 comments on commit 17c108b

Please sign in to comment.