Skip to content
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

Update realm-core to v12.5.0 #750

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
* Support `Configuration.defaultStoragePath ` for getting the platform specific storage paths. ([#665](https://github.com/realm/realm-dart/pull/665))
* Support `App.deleteUser ` for deleting user accounts. ([#679](https://github.com/realm/realm-dart/pull/679))
* Support Apple, Facebook and Google authentication. ([#740](https://github.com/realm/realm-dart/pull/740))
* Allow multiple anonymous sessions. When using anonymous authentication you can now easily log in with a different anonymous user than last time. ([#750](https://github.com/realm/realm-dart/pull/750)).

### Internal
* Added a command to `realm_dart` for deleting Atlas App Services applications. Usage: `dart run realm_dart delete-apps`. By default it will delete apps from `http://localhost:9090` which is the endpoint of the local docker image. If `--atlas-cluster` is provided, it will authenticate, delete the application from the provided cluster. (PR [#663](https://github.com/realm/realm-dart/pull/663))
* Uses Realm Core v12.5.0


## 0.3.1+beta (2022-06-07)

Expand Down
12 changes: 8 additions & 4 deletions lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ enum AuthProviderType {
/// For authenticating without credentials.
anonymous,

/// For authenticating without credentials using a new anonymous user.
anonymousNoReuse,

/// Authenticate with Apple Id
apple,

Expand All @@ -36,7 +39,7 @@ enum AuthProviderType {

/// Authenticate with Google account
google,

_custom,

/// For authenticating with an email and a password.
Expand All @@ -54,10 +57,11 @@ class Credentials {
final AuthProviderType provider;

/// 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://docs.mongodb.com/realm/authentication/anonymous)
Credentials.anonymous()
: _handle = realmCore.createAppCredentialsAnonymous(),
provider = AuthProviderType.anonymous;
Credentials.anonymous({bool reuseCredentials = true})
: _handle = realmCore.createAppCredentialsAnonymous(reuseCredentials),
provider = reuseCredentials ? AuthProviderType.anonymous : AuthProviderType.anonymousNoReuse;

/// Returns a [Credentials] object that can be used to authenticate a user with a Google account using an id token.
Credentials.apple(String idToken)
Expand Down
78 changes: 48 additions & 30 deletions lib/src/native/realm_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,21 @@ class RealmLibrary {
ffi.Pointer<realm_app_t> Function(ffi.Pointer<realm_app_config_t>,
ffi.Pointer<realm_sync_client_config_t>)>();

ffi.Pointer<realm_app_credentials_t> realm_app_credentials_new_anonymous() {
return _realm_app_credentials_new_anonymous();
ffi.Pointer<realm_app_credentials_t> realm_app_credentials_new_anonymous(
bool reuse_credentials,
) {
return _realm_app_credentials_new_anonymous(
reuse_credentials,
);
}

late final _realm_app_credentials_new_anonymousPtr = _lookup<
ffi.NativeFunction<ffi.Pointer<realm_app_credentials_t> Function()>>(
'realm_app_credentials_new_anonymous');
ffi.NativeFunction<
ffi.Pointer<realm_app_credentials_t> Function(
ffi.Bool)>>('realm_app_credentials_new_anonymous');
late final _realm_app_credentials_new_anonymous =
_realm_app_credentials_new_anonymousPtr
.asFunction<ffi.Pointer<realm_app_credentials_t> Function()>();
.asFunction<ffi.Pointer<realm_app_credentials_t> Function(bool)>();

ffi.Pointer<realm_app_credentials_t> realm_app_credentials_new_apple(
ffi.Pointer<ffi.Char> id_token,
Expand Down Expand Up @@ -6157,7 +6162,7 @@ class RealmLibrary {
ffi.Pointer<realm_query_t> arg0,
ffi.Pointer<ffi.Char> query_string,
int num_args,
ffi.Pointer<realm_value_t> args,
ffi.Pointer<realm_query_arg_t> args,
) {
return _realm_query_append_query(
arg0,
Expand All @@ -6173,11 +6178,11 @@ class RealmLibrary {
ffi.Pointer<realm_query_t>,
ffi.Pointer<ffi.Char>,
ffi.Size,
ffi.Pointer<realm_value_t>)>>('realm_query_append_query');
ffi.Pointer<realm_query_arg_t>)>>('realm_query_append_query');
late final _realm_query_append_query =
_realm_query_append_queryPtr.asFunction<
ffi.Pointer<realm_query_t> Function(ffi.Pointer<realm_query_t>,
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_value_t>)>();
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_query_arg_t>)>();

/// Count the number of objects found by this query.
bool realm_query_count(
Expand Down Expand Up @@ -6301,7 +6306,7 @@ class RealmLibrary {
int target_table,
ffi.Pointer<ffi.Char> query_string,
int num_args,
ffi.Pointer<realm_value_t> args,
ffi.Pointer<realm_query_arg_t> args,
) {
return _realm_query_parse(
arg0,
Expand All @@ -6319,10 +6324,10 @@ class RealmLibrary {
realm_class_key_t,
ffi.Pointer<ffi.Char>,
ffi.Size,
ffi.Pointer<realm_value_t>)>>('realm_query_parse');
ffi.Pointer<realm_query_arg_t>)>>('realm_query_parse');
late final _realm_query_parse = _realm_query_parsePtr.asFunction<
ffi.Pointer<realm_query_t> Function(ffi.Pointer<realm_t>, int,
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_value_t>)>();
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_query_arg_t>)>();

/// Parse a query string and bind it to a list.
///
Expand All @@ -6340,7 +6345,7 @@ class RealmLibrary {
ffi.Pointer<realm_list_t> target_list,
ffi.Pointer<ffi.Char> query_string,
int num_args,
ffi.Pointer<realm_value_t> args,
ffi.Pointer<realm_query_arg_t> args,
) {
return _realm_query_parse_for_list(
target_list,
Expand All @@ -6356,11 +6361,11 @@ class RealmLibrary {
ffi.Pointer<realm_list_t>,
ffi.Pointer<ffi.Char>,
ffi.Size,
ffi.Pointer<realm_value_t>)>>('realm_query_parse_for_list');
ffi.Pointer<realm_query_arg_t>)>>('realm_query_parse_for_list');
late final _realm_query_parse_for_list =
_realm_query_parse_for_listPtr.asFunction<
ffi.Pointer<realm_query_t> Function(ffi.Pointer<realm_list_t>,
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_value_t>)>();
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_query_arg_t>)>();

/// Parse a query string and bind it to another query result.
///
Expand All @@ -6379,7 +6384,7 @@ class RealmLibrary {
ffi.Pointer<realm_results_t> target_results,
ffi.Pointer<ffi.Char> query_string,
int num_args,
ffi.Pointer<realm_value_t> args,
ffi.Pointer<realm_query_arg_t> args,
) {
return _realm_query_parse_for_results(
target_results,
Expand All @@ -6390,16 +6395,17 @@ class RealmLibrary {
}

late final _realm_query_parse_for_resultsPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<realm_query_t> Function(
ffi.Pointer<realm_results_t>,
ffi.Pointer<ffi.Char>,
ffi.Size,
ffi.Pointer<realm_value_t>)>>('realm_query_parse_for_results');
ffi.NativeFunction<
ffi.Pointer<realm_query_t> Function(
ffi.Pointer<realm_results_t>,
ffi.Pointer<ffi.Char>,
ffi.Size,
ffi.Pointer<realm_query_arg_t>)>>(
'realm_query_parse_for_results');
late final _realm_query_parse_for_results =
_realm_query_parse_for_resultsPtr.asFunction<
ffi.Pointer<realm_query_t> Function(ffi.Pointer<realm_results_t>,
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_value_t>)>();
ffi.Pointer<ffi.Char>, int, ffi.Pointer<realm_query_arg_t>)>();

/// Refresh the view of the realm file.
///
Expand Down Expand Up @@ -9881,14 +9887,15 @@ typedef realm_async_open_task_t = realm_async_open_task;

abstract class realm_auth_provider {
static const int RLM_AUTH_PROVIDER_ANONYMOUS = 0;
static const int RLM_AUTH_PROVIDER_FACEBOOK = 1;
static const int RLM_AUTH_PROVIDER_GOOGLE = 2;
static const int RLM_AUTH_PROVIDER_APPLE = 3;
static const int RLM_AUTH_PROVIDER_CUSTOM = 4;
static const int RLM_AUTH_PROVIDER_EMAIL_PASSWORD = 5;
static const int RLM_AUTH_PROVIDER_FUNCTION = 6;
static const int RLM_AUTH_PROVIDER_USER_API_KEY = 7;
static const int RLM_AUTH_PROVIDER_SERVER_API_KEY = 8;
static const int RLM_AUTH_PROVIDER_ANONYMOUS_NO_REUSE = 1;
static const int RLM_AUTH_PROVIDER_FACEBOOK = 2;
static const int RLM_AUTH_PROVIDER_GOOGLE = 3;
static const int RLM_AUTH_PROVIDER_APPLE = 4;
static const int RLM_AUTH_PROVIDER_CUSTOM = 5;
static const int RLM_AUTH_PROVIDER_EMAIL_PASSWORD = 6;
static const int RLM_AUTH_PROVIDER_FUNCTION = 7;
static const int RLM_AUTH_PROVIDER_USER_API_KEY = 8;
static const int RLM_AUTH_PROVIDER_SERVER_API_KEY = 9;
}

class realm_binary extends ffi.Struct {
Expand Down Expand Up @@ -10349,6 +10356,17 @@ abstract class realm_property_type {

class realm_query extends ffi.Opaque {}

class realm_query_arg extends ffi.Struct {
@ffi.Size()
external int nb_args;

@ffi.Bool()
external bool is_list;

external ffi.Pointer<realm_value_t> arg;
}

typedef realm_query_arg_t = realm_query_arg;
typedef realm_query_t = realm_query;

class realm_results extends ffi.Opaque {}
Expand Down
23 changes: 15 additions & 8 deletions lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ class _RealmCore {
RealmResultsHandle queryClass(Realm realm, int classKey, String query, List<Object> args) {
return using((arena) {
final length = args.length;
final argsPointer = arena<realm_value_t>(length);
final argsPointer = arena<realm_query_arg_t>(length);
for (var i = 0; i < length; ++i) {
_intoRealmValue(args[i], argsPointer.elementAt(i), arena);
_intoRealmQueryArg(args[i], argsPointer.elementAt(i), arena);
}
final queryHandle = RealmQueryHandle._(_realmLib.invokeGetPointer(
() => _realmLib.realm_query_parse(
Expand All @@ -606,9 +606,9 @@ class _RealmCore {
RealmResultsHandle queryResults(RealmResults target, String query, List<Object> args) {
return using((arena) {
final length = args.length;
final argsPointer = arena<realm_value_t>(length);
final argsPointer = arena<realm_query_arg_t>(length);
for (var i = 0; i < length; ++i) {
_intoRealmValue(args[i], argsPointer.elementAt(i), arena);
_intoRealmQueryArg(args[i], argsPointer.elementAt(i), arena);
}
final queryHandle = RealmQueryHandle._(_realmLib.invokeGetPointer(
() => _realmLib.realm_query_parse_for_results(
Expand All @@ -630,9 +630,9 @@ class _RealmCore {
RealmResultsHandle queryList(RealmList target, String query, List<Object> args) {
return using((arena) {
final length = args.length;
final argsPointer = arena<realm_value_t>(length);
final argsPointer = arena<realm_query_arg_t>(length);
for (var i = 0; i < length; ++i) {
_intoRealmValue(args[i], argsPointer.elementAt(i), arena);
_intoRealmQueryArg(args[i], argsPointer.elementAt(i), arena);
}
final queryHandle = RealmQueryHandle._(_realmLib.invokeGetPointer(
() => _realmLib.realm_query_parse_for_list(
Expand Down Expand Up @@ -919,8 +919,8 @@ class _RealmCore {
});
}

RealmAppCredentialsHandle createAppCredentialsAnonymous() {
return RealmAppCredentialsHandle._(_realmLib.realm_app_credentials_new_anonymous());
RealmAppCredentialsHandle createAppCredentialsAnonymous(bool reuseCredentials) {
return RealmAppCredentialsHandle._(_realmLib.realm_app_credentials_new_anonymous(reuseCredentials));
}

RealmAppCredentialsHandle createAppCredentialsEmailPassword(String email, String password) {
Expand Down Expand Up @@ -1852,6 +1852,13 @@ Pointer<realm_value_t> _toRealmValue(Object? value, Allocator allocator) {
const int _microsecondsPerSecond = 1000 * 1000;
const int _nanosecondsPerMicrosecond = 1000;

void _intoRealmQueryArg(Object? value, Pointer<realm_query_arg_t> realm_query_arg, Allocator allocator) {
realm_query_arg.ref.arg = allocator<realm_value_t>();
realm_query_arg.ref.nb_args = 1;
realm_query_arg.ref.is_list = false;
_intoRealmValue(value, realm_query_arg.ref.arg, allocator);
}

void _intoRealmValue(Object? value, Pointer<realm_value_t> realm_value, Allocator allocator) {
if (value == null) {
realm_value.ref.type = realm_value_type.RLM_TYPE_NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/realm-core
Submodule realm-core updated 41 files
+25 −0 CHANGELOG.md
+1 −3 Jenkinsfile
+1 −1 Package.swift
+1 −1 dependencies.list
+3 −0 evergreen/config_overrides.json
+59 −38 evergreen/install_baas.sh
+11 −5 src/realm.h
+2 −2 src/realm/array_basic.hpp
+22 −19 src/realm/object-store/audit.mm
+3 −2 src/realm/object-store/c_api/app.cpp
+50 −33 src/realm/object-store/c_api/query.cpp
+3 −2 src/realm/object-store/object_schema.cpp
+1 −1 src/realm/object-store/shared_realm.cpp
+4 −2 src/realm/object-store/sync/app_credentials.cpp
+2 −1 src/realm/object-store/sync/app_credentials.hpp
+155 −44 src/realm/parser/driver.cpp
+37 −9 src/realm/parser/driver.hpp
+247 −222 src/realm/parser/generated/query_bison.cpp
+2 −2 src/realm/parser/generated/query_bison.hpp
+15 −16 src/realm/parser/generated/query_flex.cpp
+3 −4 src/realm/parser/generated/query_flex.hpp
+6 −3 src/realm/parser/query_bison.yy
+29 −1 src/realm/parser/query_parser.hpp
+1 −1 src/realm/query_expression.cpp
+271 −113 src/realm/query_expression.hpp
+2 −0 src/realm/status_with.hpp
+3 −1 src/realm/sync/client.cpp
+8 −5 src/realm/sync/subscriptions.cpp
+3 −0 src/realm/sync/subscriptions.hpp
+8 −5 src/realm/table.hpp
+6 −0 src/realm/util/bind_ptr.hpp
+10 −9 src/realm/util/serializer.cpp
+1 −1 src/realm/util/serializer.hpp
+1 −0 src/realm/util/websocket.cpp
+62 −33 test/object-store/c_api/c_api.cpp
+1 −1 test/object-store/main.cpp
+168 −184 test/object-store/realm.cpp
+3 −3 test/object-store/schema.cpp
+21 −0 test/object-store/sync/app.cpp
+310 −38 test/test_parser.cpp
+1 −1 test/test_query.cpp
10 changes: 10 additions & 0 deletions test/credentials_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ Future<void> main([List<String>? args]) async {
expect(credentials.provider, AuthProviderType.anonymous);
});

baasTest('Anonymous - new user', (configuration) async {
final app = App(configuration);
final user1 = await app.logIn(Credentials.anonymous());
final user2 = await app.logIn(Credentials.anonymous());
final user3 = await app.logIn(Credentials.anonymous(reuseCredentials: false));

expect(user1, user2);
expect(user1, isNot(user3));
});

test('Credentials email/password', () {
final credentials = Credentials.emailPassword("test@email.com", "000000");
expect(credentials.provider, AuthProviderType.emailPassword);
Expand Down