Skip to content

Commit b4e14f7

Browse files
committed
chore!: Migrate core (#1599)
commit-id:59b50639
1 parent 2c69e5d commit b4e14f7

File tree

497 files changed

+2857
-4773
lines changed

Some content is hidden

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

497 files changed

+2857
-4773
lines changed

.circleci/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,8 @@ workflows:
228228
"amplify_authenticator",
229229
"amplify_core",
230230
"amplify_datastore",
231-
"amplify_datastore_plugin_interface",
232231
"amplify_flutter",
233-
"amplify_storage_plugin_interface",
234-
"amplify_storage_s3",
232+
"amplify_storage_s3"
235233
]
236234
- unit_test_android:
237235
matrix:

example/lib/Views/ImagePreview.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// permissions and limitations under the License.
1414
//
1515

16-
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
1716
import 'package:amplify_flutter/amplify_flutter.dart';
1817
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
1918
import 'package:flutter/material.dart';

example/lib/Views/SignInView.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
1716
import 'package:amplify_flutter/amplify_flutter.dart';
1817
import 'package:flutter/material.dart';
1918

example/lib/Views/UserView.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
1716
import 'package:amplify_flutter/amplify_flutter.dart';
1817
import 'package:flutter/material.dart';
1918
import 'package:sample_app/Pages/LandingPage.dart';

packages/amplify/amplify_flutter/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import 'package:amplify_flutter/amplify_flutter.dart';
17+
import 'package:aws_common/aws_common.dart';
1718
import 'package:flutter/foundation.dart';
1819
import 'package:flutter/material.dart';
1920

packages/amplify/amplify_flutter/example/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ description: Demonstrates how to use the amplify plugin.
66
publish_to: "none" # Remove this line if you wish to publish to pub.dev
77

88
environment:
9-
sdk: ">=2.12.0 <3.0.0"
9+
sdk: ">=2.15.0 <3.0.0"
10+
flutter: ">=2.10.0"
1011

1112
dependencies:
1213
amplify_flutter:
@@ -16,7 +17,7 @@ dependencies:
1617
# The example app is bundled with the plugin so we use a path dependency on
1718
# the parent directory to use the current plugin's version.
1819
path: ../
19-
20+
aws_common: ^0.1.0
2021
flutter:
2122
sdk: flutter
2223

packages/amplify/amplify_flutter/lib/amplify_flutter.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,6 @@ export 'package:amplify_core/amplify_core.dart';
2222
// Amplify interface
2323
export 'src/amplify_impl.dart';
2424

25-
// Category interfaces
26-
export 'src/categories/amplify_categories.dart';
27-
28-
// Config
29-
export 'src/config/amplify_config.dart';
30-
export 'src/config/amplify_plugin_config.dart' hide UnknownPluginConfigFactory;
31-
export 'src/config/amplify_plugin_registry.dart';
32-
export 'src/config/analytics/analytics_config.dart';
33-
export 'src/config/api/api_config.dart';
34-
export 'src/config/auth/auth_config.dart';
35-
export 'src/config/config_map.dart';
36-
export 'src/config/storage/storage_config.dart';
37-
38-
// Utilities
39-
export 'src/utils/equatable.dart';
40-
export 'src/utils/json.dart';
41-
export 'src/utils/serializable.dart';
42-
4325
/// Top level singleton Amplify object.
4426
AmplifyClass get Amplify => AmplifyClass.instance;
4527

packages/amplify/amplify_flutter/lib/src/amplify_hub.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import 'dart:async';
1717

1818
import 'package:amplify_core/amplify_core.dart';
19+
import 'package:aws_common/aws_common.dart';
1920

2021
import '../amplify_flutter.dart';
2122

packages/amplify/amplify_flutter/lib/src/amplify_impl.dart

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,73 @@
1515

1616
import 'dart:async';
1717
import 'dart:convert';
18+
import 'dart:io';
1819

19-
import 'package:amplify_analytics_plugin_interface/amplify_analytics_plugin_interface.dart';
20-
import 'package:amplify_api_plugin_interface/amplify_api_plugin_interface.dart';
21-
import 'package:amplify_auth_plugin_interface/amplify_auth_plugin_interface.dart';
2220
import 'package:amplify_core/amplify_core.dart';
23-
import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart';
24-
import 'package:amplify_flutter/src/config/amplify_config.dart';
25-
import 'package:amplify_storage_plugin_interface/amplify_storage_plugin_interface.dart';
21+
import 'package:aws_common/aws_common.dart';
2622
import 'package:flutter/foundation.dart';
2723
import 'package:flutter/services.dart';
28-
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
2924

3025
import 'amplify_hub.dart';
31-
import 'categories/amplify_categories.dart';
3226

3327
part 'method_channel_amplify.dart';
3428

29+
/// {@template amplify_flutter.amplify_class}
3530
/// Amplify singleton class.
3631
///
3732
/// This class can be extended to create a custom Amplify implementation.
3833
/// The default Amplify implementation will use method channels, and will
3934
/// only support iOS and Android platforms.
40-
class AmplifyClass extends PlatformInterface {
35+
/// {@endtemplate}
36+
abstract class AmplifyClass {
37+
/// {@macro amplify_flutter.amplify_class}
38+
factory AmplifyClass() {
39+
if (zIsWeb || Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
40+
throw UnsupportedError('This platform is not supported yet');
41+
}
42+
return MethodChannelAmplify();
43+
}
44+
4145
/// The Auth category.
42-
final AuthCategory Auth = const AuthCategory();
46+
final AuthCategory Auth = AuthCategory();
4347

4448
/// The Analytics category.
45-
final AnalyticsCategory Analytics = const AnalyticsCategory();
49+
final AnalyticsCategory Analytics = AnalyticsCategory();
4650

4751
/// The Storage category.
48-
final StorageCategory Storage = const StorageCategory();
52+
final StorageCategory Storage = StorageCategory();
4953

5054
/// The DataStore category.
51-
final DataStoreCategory DataStore = const DataStoreCategory();
55+
final DataStoreCategory DataStore = DataStoreCategory();
5256

5357
/// The API category.
54-
final APICategory API = const APICategory();
58+
final APICategory API = APICategory();
5559

5660
/// The Amplify event hub.
5761
final AmplifyHub Hub = AmplifyHub();
5862

63+
final _configCompleter = Completer<AmplifyConfig>();
64+
5965
/// Adds one plugin at a time. Note: this method can only
6066
/// be called before Amplify has been configured. Customers are expected
6167
/// to check the configuration state by calling `Amplify.isConfigured`
6268
///
6369
/// Throws AmplifyAlreadyConfiguredException if
6470
/// this method is called after configure (e.g. during hot reload).
65-
Future<void> addPlugin(AmplifyPluginInterface plugin) async {
66-
return instance.addPlugin(plugin);
67-
}
71+
Future<void> addPlugin(AmplifyPluginInterface plugin);
6872

6973
/// Adds multiple plugins at the same time. Note: this method can only
7074
/// be called before Amplify has been configured. Customers are expected
7175
/// to check the configuration state by calling `Amplify.isConfigured`
7276
Future<void> addPlugins(List<AmplifyPluginInterface> plugins) {
73-
return instance.addPlugins(plugins);
77+
return Future.wait(plugins.map(addPlugin), eagerError: true);
7478
}
7579

7680
/// Returns whether Amplify has been configured or not.
77-
bool get isConfigured {
78-
return instance.isConfigured;
79-
}
81+
bool get isConfigured => _configCompleter.isCompleted;
8082

8183
/// A future when completes when Amplify has been successfully configured.
82-
Future<AmplifyConfig> get asyncConfig {
83-
return instance.asyncConfig;
84-
}
84+
Future<AmplifyConfig> get asyncConfig => _configCompleter.future;
8585

8686
/// Configures Amplify with the provided configuration string.
8787
/// **This method can only be called once**, after all the plugins
@@ -92,29 +92,53 @@ class AmplifyClass extends PlatformInterface {
9292
/// Throws AmplifyAlreadyConfiguredException if
9393
/// this method is called again (e.g. during hot reload).
9494
Future<void> configure(String configuration) async {
95-
return instance.configure(configuration);
95+
if (isConfigured) {
96+
throw const AmplifyAlreadyConfiguredException(
97+
'Amplify has already been configured and re-configuration is not supported.',
98+
recoverySuggestion:
99+
'Check if Amplify is already configured using Amplify.isConfigured.',
100+
);
101+
}
102+
103+
final AmplifyConfig amplifyConfig;
104+
try {
105+
final json = jsonDecode(configuration) as Map;
106+
amplifyConfig = AmplifyConfig.fromJson(json.cast());
107+
} on FormatException catch (e) {
108+
throw AmplifyException(
109+
'The provided configuration is not a valid json. Check underlyingException.',
110+
recoverySuggestion:
111+
'Inspect your amplifyconfiguration.dart and ensure that the string is proper json',
112+
underlyingException: e.toString(),
113+
);
114+
}
115+
116+
await configurePlatform(configuration);
117+
_configCompleter.complete(amplifyConfig);
96118
}
97119

120+
/// Configures the platform-specific implementation of Amplify using the
121+
/// registered [config].
122+
@protected
123+
Future<void> configurePlatform(String config);
124+
98125
/// Constructs a Core platform.
99126
/// Internal Use Only
100127
@protected
101-
AmplifyClass.protected() : super(token: _token);
128+
AmplifyClass.protected();
102129

103-
static final Object _token = Object();
130+
/// The instance of [AmplifyClass] to use.
131+
///
132+
/// Defaults to the platform-specific implementation.
133+
static AmplifyClass instance = AmplifyClass();
104134

105-
static AmplifyClass _instance = MethodChannelAmplify();
135+
/// The library version.
136+
String get version => '0.5.1';
106137

107-
/// The default instance of [AmplifyClass] to use.
108-
///
109-
/// Defaults to [MethodChannelAmplify].
110-
static AmplifyClass get instance => _instance;
111-
112-
/// Platform-specific plugins should set this with their own platform-specific
113-
/// class that extends [AmplifyClass] when they register themselves.
114-
static set instance(AmplifyClass instance) {
115-
PlatformInterface.verifyToken(instance, _token);
116-
_instance = instance;
117-
}
138+
/// Resets the Amplify implementation, removing all traces of Amplify from
139+
/// the device.
140+
@visibleForTesting
141+
Future<void> reset();
118142
}
119143

120144
// ignore_for_file: non_constant_identifier_names

packages/amplify/amplify_flutter/lib/src/categories/amplify_categories.dart

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)