From 08639fc8538cc30c36d7747b64de678df19ae804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Mon, 16 May 2022 14:50:57 +0200 Subject: [PATCH] Change factories on Configuration to static methods --- lib/src/configuration.dart | 46 ++++++++++++++++++++++++++---------- test/configuration_test.dart | 4 ++-- test/subscription_test.dart | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index dc0ec10e83..a181975be0 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -103,39 +103,61 @@ abstract class Configuration { final List? encryptionKey; /// Constructs a [LocalConfiguration] - factory Configuration.local( + static LocalConfiguration local( List schemaObjects, { InitialDataCallback? initialDataCallback, - int schemaVersion, + int schemaVersion = 0, String? fifoFilesFallbackPath, String? path, - bool disableFormatUpgrade, - bool isReadOnly, + bool disableFormatUpgrade = false, + bool isReadOnly = false, ShouldCompactCallback? shouldCompactCallback, - }) = LocalConfiguration; + }) => + LocalConfiguration._( + schemaObjects, + initialDataCallback: initialDataCallback, + schemaVersion: schemaVersion, + fifoFilesFallbackPath: fifoFilesFallbackPath, + path: path, + disableFormatUpgrade: disableFormatUpgrade, + isReadOnly: isReadOnly, + shouldCompactCallback: shouldCompactCallback, + ); /// Constructs a [InMemoryConfiguration] - factory Configuration.inMemory( + static InMemoryConfiguration inMemory( List schemaObjects, String identifier, { String? fifoFilesFallbackPath, String? path, - }) = InMemoryConfiguration; + }) => + InMemoryConfiguration._( + schemaObjects, + identifier, + fifoFilesFallbackPath: fifoFilesFallbackPath, + path: path, + ); /// Constructs a [FlexibleSyncConfiguration] - factory Configuration.sync( + static FlexibleSyncConfiguration sync( User user, List schemaObjects, { String? fifoFilesFallbackPath, String? path, - }) = FlexibleSyncConfiguration; + }) => + FlexibleSyncConfiguration._( + user, + schemaObjects, + fifoFilesFallbackPath: fifoFilesFallbackPath, + path: path, + ); } /// [LocalConfiguration] is used to open local [Realm] instances, /// that are persisted across runs. /// {@category Configuration} class LocalConfiguration extends Configuration { - LocalConfiguration( + LocalConfiguration._( List schemaObjects, { this.initialDataCallback, this.schemaVersion = 0, @@ -195,7 +217,7 @@ class FlexibleSyncConfiguration extends Configuration { SessionStopPolicy _sessionStopPolicy = SessionStopPolicy.afterChangesUploaded; - FlexibleSyncConfiguration( + FlexibleSyncConfiguration._( this.user, List schemaObjects, { String? fifoFilesFallbackPath, @@ -216,7 +238,7 @@ extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration { /// are temporary to running process. /// {@category Configuration} class InMemoryConfiguration extends Configuration { - InMemoryConfiguration( + InMemoryConfiguration._( List schemaObjects, this.identifier, { String? fifoFilesFallbackPath, diff --git a/test/configuration_test.dart b/test/configuration_test.dart index 6537f2298a..b825c9990c 100644 --- a/test/configuration_test.dart +++ b/test/configuration_test.dart @@ -64,10 +64,10 @@ Future main([List? args]) async { }); test('Configuration get/set schema version', () { - final config = LocalConfiguration([Car.schema]); + final config = Configuration.local([Car.schema]); expect(config.schemaVersion, equals(0)); - final explicitSchemaConfig = LocalConfiguration([Car.schema], schemaVersion: 3); + final explicitSchemaConfig = Configuration.local([Car.schema], schemaVersion: 3); expect(explicitSchemaConfig.schemaVersion, equals(3)); }); diff --git a/test/subscription_test.dart b/test/subscription_test.dart index ccedc223ab..b9e9b4b0c1 100644 --- a/test/subscription_test.dart +++ b/test/subscription_test.dart @@ -36,7 +36,7 @@ void testSubscriptions(String name, FutureOr Function(Realm) tester) async final app = App(appConfiguration); final credentials = Credentials.anonymous(); final user = await app.logIn(credentials); - final configuration = FlexibleSyncConfiguration(user, [Task.schema, Schedule.schema])..sessionStopPolicy = SessionStopPolicy.immediately; + final configuration = Configuration.sync(user, [Task.schema, Schedule.schema])..sessionStopPolicy = SessionStopPolicy.immediately; final realm = getRealm(configuration); await tester(realm); });