Skip to content

Commit 5e4e6a7

Browse files
author
Kasper Overgård Nielsen
authored
RDART-930: Refactor handles (#1550)
* Refactor handles subscription.dart * Refactor: use import over part for handle_base.dart * Fix regression: Check if close on handle deref * TMP: Skip some tests (something broke with RootedHandle) * Ups! * Wip * After rebase * wip * Fix after rebase * Revert "TMP: Skip some tests (something broke with RootedHandle)" This reverts commit 5081217. * Use dart_test.yaml to configure tags. Make baas a tag instead of a prefix. Simplify * Fix nullPtr related bug * Doh! I'll go die in shame!! * Refactor RealmHandle * Refactor ConfigHandle * Refactor _RealmQueryHandler (now QueryHandle) * Refactor RealmObjectHandle (now ObjectHandle) * Refactor RealmResultHandle (now ResultsHandle) * More RealmHandle stuff * Don't need Tuple * Expose disableAutoRefreshForTesting * Refactor UserHandle * RealmHandle.findAll * Realm.find/.findExiting/.renameProperty * Drop superfluous this. * Refactor AppHandle * Refactor SchedulerHandle * Move config handles * Refactor SessionHandle * UserHandle.linkCredentials/.createApiKey/.fetchApiKey/.fetchAllApiKeys.deleteApiKey/.disableApiKey/.enableApiKey * Refactor RealmListHandle (now ListHandle) * Refactor RealmSetHandle (now SetHandle) * Refactor RealmAppCredentialsHandle (now CredentialsHandle) * WIP * WIP2 * Organize imports * ResultsHandle stuff * More UserHandle stuff * subscribeForSchemaNotification (something rubs me the wrong way about this) * Move MapHandle.query * More ObjectHandle stuff * Move callback functions into handle files * Move resolveX to XHandle.resolveIn * Make a bunch of function public in prep for getting rid of parts * Refactor XChangesHandle * Use CredentialsHandle not Credentils * Traffic in ResultsHandle not RealmResult + dart fix stuff * Split part files * Move XTokenHandles * toNative extension method replaces toRealmValue function * Replace last use of deprecated Pointer.elementAt(i) * More RealmHandle stuff * Replace invokeGetBool and invokeGetPointer * Run melos custom_format * Move callAppFunction stuff * Refactor equals * Move raiseIfNull to HandleBase ctor. Rename to be explicit about call to getLastError * Completely unrelated spelling corrections in CHANGELOG * Seperate AsyncOpenTaskHandle and NotificationHandle from realm_core.dart * moving guardSynchronousCallback and getApp out of realm_core.dart * Split native convertion functions into separate files * Last leg.. for now * PR feedback * Fix rebase * Tweat memEquals perf test * fixup! Last leg.. for now * Fix after rebase * more PR feedback
1 parent 14c7bd6 commit 5e4e6a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4642
-4245
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"geospatial",
2626
"HRESULT",
2727
"keepalive",
28+
"keypaths",
2829
"loggable",
2930
"maccatalyst",
3031
"mugaritz",

CHANGELOG.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
* Fixed a `DecryptionFailed` exception thrown when opening a small (<4k of data) Realm generated on a device with a page size of 4k if it was bundled and opened on a device with a larger page size.
8383
* Fixed an issue during a subsequent open of an encrypted Realm for some rare allocation patterns when the top ref was within ~50 bytes of the end of a page. This could manifest as a DecryptionFailed exception or as an assertion: `encrypted_file_mapping.hpp:183: Assertion failed: local_ndx < m_page_state.size()`.
8484
* Schema initialization could hit an assertion failure if the sync client applied a downloaded changeset while the Realm file was in the process of being opened. (Core 14.6.0)
85-
* Improve perfomance of "chained OR equality" queries for UUID/ObjectId types and RQL parsed "IN" queries on string/int/uuid/objectid types. (Core 14.6.0)
85+
* Improve performance of "chained OR equality" queries for UUID/ObjectId types and RQL parsed "IN" queries on string/int/uuid/objectid types. (Core 14.6.0)
8686
* Fixed a bug when running a IN query (or a query of the pattern `x == 1 OR x == 2 OR x == 3`) when evaluating on a string property with an empty string in the search condition. Matches with an empty string would have been evaluated as if searching for a null string instead. (Core 14.6.2)
8787

8888
### Compatibility
@@ -184,9 +184,9 @@
184184
```
185185
* Removed `SchemaObject.properties` - instead, `SchemaObject` is now an iterable collection of `Property`. (Issue [#1449](https://github.com/realm/realm-dart/issues/1449))
186186
* `SyncProgress.transferredBytes` and `SyncProgress.transferableBytes` have been consolidated into `SyncProgress.progressEstimate`. The values reported previously were incorrect and did not accurately represent bytes either. The new field better conveys the uncertainty around the progress being reported. With this release, we're reporting accurate estimates for upload progress, but estimating downloads is still unreliable. A future server and SDK release will add better estimations for download progress. (Issue [#1562](https://github.com/realm/realm-dart/issues/1562))
187-
* `Realm.logger` is no longer settable, and no longer implements `Logger` from package `logging`. In particular you can no longer call `Realm.logger.level =`. Instead you should call `Realm.logger.setLogLevel(RealmLogLevel level, {RealmLogCategory? category})` that takes an optional category. If no category is exlicitly given, then `RealmLogCategory.realm` is assumed.
187+
* `Realm.logger` is no longer settable, and no longer implements `Logger` from package `logging`. In particular you can no longer call `Realm.logger.level =`. Instead you should call `Realm.logger.setLogLevel(RealmLogLevel level, {RealmLogCategory? category})` that takes an optional category. If no category is explicitly given, then `RealmLogCategory.realm` is assumed.
188188

189-
Also, note that setting a level is no longer local to the current isolate, but shared accross all isolates. At the core level there is just one process wide logger.
189+
Also, note that setting a level is no longer local to the current isolate, but shared across all isolates. At the core level there is just one process wide logger.
190190

191191
Categories form a hierarchy and setting the log level of a parent category will override the level of its children. The hierarchy is exposed in a type safe manner with:
192192
```dart
@@ -928,7 +928,7 @@ class _Address {
928928
* Queries on results didn't filter the existing results. ([#908](https://github.com/realm/realm-dart/issues/908)).
929929
Example
930930
```dart
931-
expect(realm.query<Person>('FALSEPREDICATE').query('TRUEPREDICATE'), isEmpty); //<-- Fails if a Persion object exists
931+
expect(realm.query<Person>('FALSEPREDICATE').query('TRUEPREDICATE'), isEmpty); //<-- Fails if a Person object exists
932932
```
933933
* Fixed copying of native structs for session errors and http requests. ([#924](https://github.com/realm/realm-dart/pull/924))
934934
* Fixed a crash when closing the SyncSession on App instance teardown. ([#5752](https://github.com/realm/realm-core/issues/5752))
@@ -1091,7 +1091,7 @@ class _Address {
10911091

10921092
```dart
10931093
final subscription = realm.all<Dog>().changes.listen((changes) {
1094-
changes.inserted // indexes of inserted ojbects
1094+
changes.inserted // indexes of inserted objects
10951095
changes.modified // indexes of modified objects
10961096
changes.deleted // indexes of deleted objects
10971097
changes.newModified // indexes of modified objects after deletions and insertions are accounted for.
@@ -1231,7 +1231,7 @@ Notes: This release is a prerelease version. All API's might change without warn
12311231
Notes: This release is a prerelease version. All API's might change without warning and no guarantees are given about stability.
12321232
12331233
### Enhancements
1234-
* Completеly rewritten from the ground up with sound null safety and using Dart FFI
1234+
* Completely rewritten from the ground up with sound null safety and using Dart FFI
12351235
12361236
### Fixed
12371237
* Realm close stops internal scheduler.
@@ -1247,7 +1247,7 @@ Notes: This release is a prerelease version. All API's might change without warn
12471247
Notes: This release is a prerelease version. All API's might change without warning and no guarantees are given about stability.
12481248
12491249
### Enhancements
1250-
* Completеly rewritten from the ground up with sound null safety and using Dart FFI
1250+
* Completely rewritten from the ground up with sound null safety and using Dart FFI
12511251
12521252
### Compatibility
12531253
* Dart ^2.15 on Windows, MacOS and Linux

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ linter:
1919
rules:
2020
avoid_relative_lib_imports: false
2121
package_api_docs: true
22-
dangling_library_doc_comments: false
2322

2423
# For more information about the core and recommended set of lints, see
2524
# https://dart.dev/go/core-lints

packages/realm/bin/realm.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2021 MongoDB, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
54
import 'package:realm_dart/src/cli/main.dart' as x;
5+
66
void main(List<String> arguments) => x.main(arguments);

packages/realm_common/lib/src/realm_common_base.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,3 @@ class Backlink {
130130
final Symbol fieldName;
131131
const Backlink(this.fieldName);
132132
}
133-
134-
/// @nodoc
135-
class Tuple<T1, T2> {
136-
T1 item1;
137-
T2 item2;
138-
139-
Tuple(this.item1, this.item2);
140-
}

packages/realm_common/lib/src/realm_types.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ enum RealmCollectionType {
8686
map;
8787

8888
String get plural => switch (this) {
89-
RealmCollectionType.list => 'lists',
90-
RealmCollectionType.set => 'sets',
91-
RealmCollectionType.map => 'maps',
92-
_ => 'none'
93-
};
89+
RealmCollectionType.list => 'lists',
90+
RealmCollectionType.set => 'sets',
91+
RealmCollectionType.map => 'maps',
92+
_ => 'none',
93+
};
9494
}
9595

9696
/// A base class of all Realm errors.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2021 MongoDB, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
54
import 'package:realm_dart/src/cli/main.dart' as x;
5+
66
void main(List<String> arguments) => x.main(arguments);

packages/realm_dart/dart_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tags:
2+
baas: { timeout: 2x }

packages/realm_dart/lib/src/app.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import 'dart:io';
77
import 'dart:isolate';
88

99
import 'package:meta/meta.dart';
10-
import 'package:path/path.dart' as _path;
10+
import 'package:path/path.dart' as path;
1111

1212
import '../realm.dart';
1313
import 'credentials.dart';
1414
import 'logging.dart';
15+
import 'native/app_handle.dart';
1516
import 'native/realm_core.dart';
1617
import 'user.dart';
1718

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

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

149150
/// Create an app with a particular [AppConfiguration]. This constructor should only be used on the main isolate and,
150151
/// ideally, only once as soon as the app starts.
@@ -163,26 +164,26 @@ class App implements Finalizable {
163164
/// on the main isolate. If an App hasn't been already constructed with the same id, will return null. This method is safe to call
164165
/// on a background isolate.
165166
static App? getById(String id, {Uri? baseUrl}) {
166-
final handle = realmCore.getApp(id, baseUrl?.toString());
167+
final handle = AppHandle.get(id, baseUrl?.toString());
167168
return handle == null ? null : App._(handle);
168169
}
169170

170171
App._(this._handle);
171172

172173
static AppHandle _createApp(AppConfiguration configuration) {
173174
configuration.baseFilePath.createSync(recursive: true);
174-
return realmCore.createApp(configuration);
175+
return AppHandle.from(configuration);
175176
}
176177

177178
/// Logs in a user with the given credentials.
178179
Future<User> logIn(Credentials credentials) async {
179-
var userHandle = await realmCore.logIn(this, credentials);
180+
var userHandle = await handle.logIn(credentials.handle);
180181
return UserInternal.create(userHandle, this);
181182
}
182183

183184
/// Gets the currently logged in [User]. If none exists, `null` is returned.
184185
User? get currentUser {
185-
final userHandle = realmCore.getCurrentUser(_handle);
186+
final userHandle = _handle.currentUser;
186187
if (userHandle == null) {
187188
return null;
188189
}
@@ -191,30 +192,30 @@ class App implements Finalizable {
191192

192193
/// Gets all currently logged in users.
193194
Iterable<User> get users {
194-
return realmCore.getUsers(this).map((handle) => UserInternal.create(handle, this));
195+
return handle.users.map((handle) => UserInternal.create(handle, this));
195196
}
196197

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

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

207208
/// Switches the [currentUser] to the one specified in [user].
208209
void switchUser(User user) {
209-
realmCore.switchUser(this, user);
210+
handle.switchUser(user.handle);
210211
}
211212

212213
/// Provide a hint to this app's sync client to reconnect.
213214
/// Useful when the device has been offline and then receives a network reachability update.
214215
///
215216
/// The sync client will always attempt to reconnect eventually, this is just a hint.
216217
void reconnect() {
217-
realmCore.reconnect(this);
218+
handle.reconnect();
218219
}
219220

220221
/// Returns the current value of the base URL used to communicate with the server.
@@ -223,7 +224,7 @@ class App implements Finalizable {
223224
/// be updated with the new value until that operation has completed.
224225
@experimental
225226
Uri get baseUrl {
226-
return Uri.parse(realmCore.getBaseUrl(this));
227+
return Uri.parse(handle.baseUrl);
227228
}
228229

229230
/// Temporarily overrides the [baseUrl] value from [AppConfiguration] with a new [baseUrl] value
@@ -237,7 +238,7 @@ class App implements Finalizable {
237238
/// The App will revert to using the value in [AppConfiguration] when it is restarted.
238239
@experimental
239240
Future<void> updateBaseUrl(Uri? baseUrl) async {
240-
return await realmCore.updateBaseUrl(this, baseUrl);
241+
return await handle.updateBaseUrl(baseUrl);
241242
}
242243

243244
/// Returns an instance of [EmailPasswordAuthProvider]

packages/realm_dart/lib/src/cli/common/archive.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2021 MongoDB, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
///
54
import 'dart:io';
65
import 'package:tar/tar.dart';
76
import 'package:path/path.dart' as path;

0 commit comments

Comments
 (0)