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

feat(auth,3.0): Sealed types #2995

Merged
merged 3 commits into from
May 9, 2023
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
2 changes: 0 additions & 2 deletions packages/amplify_core/lib/amplify_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export 'src/types/exception/codegen_exception.dart';
export 'src/types/exception/error/amplify_error.dart';
export 'src/types/exception/error/configuration_error.dart';
export 'src/types/exception/error/plugin_error.dart';
export 'src/types/exception/network_exception.dart';
export 'src/types/exception/unknown_exception.dart';
export 'src/types/exception/url_launcher_exception.dart';

/// Model-based types used in datastore and API
Expand Down
40 changes: 14 additions & 26 deletions packages/amplify_core/lib/src/category/amplify_categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,17 @@ enum Category {
storage,

/// Push Notifications
pushNotifications,
}

extension CategoryName on Category {
String get name {
switch (this) {
case Category.analytics:
return 'Analytics';
case Category.api:
return 'API';
case Category.auth:
return 'Auth';
case Category.dataStore:
return 'DataStore';
case Category.hub:
return 'Hub';
case Category.storage:
return 'Storage';
case Category.pushNotifications:
return 'PushNotifications';
}
}
pushNotifications;

String get name => switch (this) {
Category.analytics => 'Analytics',
Category.api => 'API',
Category.auth => 'Auth',
Category.dataStore => 'DataStore',
Category.hub => 'Hub',
Category.storage => 'Storage',
Category.pushNotifications => 'PushNotifications',
};
}

/// Base functionality for Amplify categories.
Expand All @@ -88,11 +77,10 @@ abstract class AmplifyCategory<P extends AmplifyPluginInterface> {

@protected
P get defaultPlugin {
final plugin = plugins.firstOrNull;
if (plugin == null) {
throw _pluginNotAddedException(category.name);
if (plugins case [final singlePlugin]) {
return singlePlugin;
}
return plugin;
throw _pluginNotAddedException(category.name);
}

/// Adds a plugin to the category.
Expand Down
1 change: 1 addition & 0 deletions packages/amplify_core/lib/src/state_machine/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract base class StateMachineEvent<EventType extends Object,
EventType get type;

/// Casts this to an event of type [E].
@Deprecated('Use pattern matching instead')
E cast<E extends StateMachineEvent<EventType, StateType>>() => this as E;

/// Checks the precondition, given [currentState].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ mixin Dispatcher<E extends StateMachineEvent, S extends StateMachineState> {
) async {
final completer = dispatch(event);
final state = await completer.completed;
if (state is ErrorState) {
Error.throwWithStackTrace(state.exception, state.stackTrace);
if (state case ErrorState(:final exception, :final stackTrace)) {
Error.throwWithStackTrace(exception, stackTrace);
}
return state as SuccessState;
}
Expand Down Expand Up @@ -161,8 +161,8 @@ abstract class StateMachineManager<
) async {
final completer = accept(event);
final state = await completer.completed;
if (state is ErrorState) {
Error.throwWithStackTrace(state.exception, state.stackTrace);
if (state case ErrorState(:final exception, :final stackTrace)) {
Error.throwWithStackTrace(exception, stackTrace);
}
return state as SuccessState;
}
Expand Down
9 changes: 1 addition & 8 deletions packages/amplify_core/lib/src/types/auth/auth_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

/// Exceptions
export '../exception/auth/auth_exception.dart';
export '../exception/auth/invalid_state_exception.dart';
export '../exception/auth/not_authorized_exception.dart';
export '../exception/auth/service_exception.dart';
export '../exception/auth/session_expired_exception.dart';
export '../exception/auth/signed_out_exception.dart';
export '../exception/auth/user_cancelled_exception.dart';
export '../exception/auth/validation_exception.dart';
export '../exception/amplify_exception.dart';

/// Attributes
export 'attribute/auth_next_update_attribute_step.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
import 'package:amplify_core/amplify_core.dart';
import 'package:meta/meta.dart';

part 'auth/auth_exception.dart';
part 'auth/invalid_state_exception.dart';
part 'auth/not_authorized_exception.dart';
part 'auth/service_exception.dart';
part 'auth/session_expired_exception.dart';
part 'auth/signed_out_exception.dart';
part 'auth/user_cancelled_exception.dart';
part 'auth/validation_exception.dart';
part 'network_exception.dart';
part 'unknown_exception.dart';

/// {@template amplify_core.amplify_exception}
/// Thrown from top level Amplify APIs from the amplify-flutter package.
/// All other Amplify APIs throw subclasses of AmplifyException.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.auth_exception}
/// The base class for Auth category exceptions.
/// The class for Auth category exceptions.
/// {@endtemplate}
abstract class AuthException extends AmplifyException with AWSDebuggable {
sealed class AuthException extends AmplifyException with AWSDebuggable {
/// {@macro amplify_core.auth.auth_exception}
const AuthException(
super.message, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.invalid_state_exception}
/// Exception thrown when the requested operation is not valid in the current
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.not_authorized_exception}
/// Exception thrown when the current session is not authorized to perform an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.service_exception}
/// Exception thrown when some error occurs in the underlying service.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.session_expired_exception}
/// Exception thrown when the current session is expired.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.signed_out_exception}
/// Exception thrown when the requested operation can't be performed due to the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.user_cancelled_exception}
/// Exception thrown when a requested operation could not be completed because
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of '../amplify_exception.dart';

/// {@template amplify_core.auth.validation_exception}
/// Exception thrown when one of the input fields to an operation is invalid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of 'amplify_exception.dart';

/// {@template amplify_core.network_exception}
/// Exception thrown when the requested operation fails due to a network
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_core/amplify_core.dart';
part of 'amplify_exception.dart';

/// {@template amplify_core.unknown_exception}
/// Exception thrown when an unknown error from an underlying SDK or service is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart';
// ignore: invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/model/sign_in_parameters.dart';
import 'package:amplify_auth_cognito_dart/src/state/event/sign_in_event.dart';
import 'package:amplify_auth_cognito_dart/src/state/machines/sign_in_state_machine.dart';
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
import 'package:amplify_auth_cognito_dart/src/state/state/sign_in_state.dart';
// ignore: invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_auth_cognito_example/amplifyconfiguration.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_integration_test/amplify_integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// ignore_for_file: invalid_use_of_protected_member
// ignore_for_file: invalid_use_of_protected_member, invalid_use_of_internal_member

import 'dart:async';
import 'dart:io';
Expand All @@ -12,7 +12,7 @@ import 'package:amplify_auth_cognito/src/flows/hosted_ui/hosted_ui_platform_flut
import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform.dart';
import 'package:amplify_auth_cognito_dart/src/model/hosted_ui/oauth_parameters.dart';
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
import 'package:amplify_auth_cognito_dart/src/state/event/hosted_ui_event.dart';
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_auth_cognito_example/amplifyconfiguration.dart';
import 'package:amplify_auth_cognito_test/amplify_auth_cognito_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform
import 'package:amplify_auth_cognito_dart/src/model/hosted_ui/oauth_parameters.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/event/hosted_ui_event.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/machines/hosted_ui_state_machine.dart';
// ignore: implementation_imports, invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_secure_storage/amplify_secure_storage.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// ignore_for_file: implementation_imports
// ignore_for_file: implementation_imports, invalid_use_of_internal_member

import 'package:amplify_auth_cognito/src/credentials/legacy_credential_store_data_extension.dart';
import 'package:amplify_auth_cognito/src/native_auth_plugin.g.dart';
import 'package:amplify_auth_cognito_dart/src/credentials/legacy_credential_provider.dart';
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_core/src/config/auth/cognito/credentials_provider.dart';
import 'package:amplify_core/src/config/auth/cognito/oauth.dart';
import 'package:amplify_core/src/config/auth/cognito/user_pool.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:amplify_auth_cognito/src/credentials/legacy_credential_provider_
import 'package:amplify_auth_cognito_dart/src/credentials/legacy_credential_provider.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
// ignore: implementation_imports, invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_core/amplify_core.dart';

/// {@template amplify_auth_cognito.legacy_credential_provider_impl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart';
import 'package:amplify_auth_cognito_dart/src/credentials/legacy_credential_provider.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
// ignore: implementation_imports, invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:async/async.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_auth_cognito/src/native_auth_plugin.g.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
// ignore: implementation_imports, invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_core/amplify_core.dart';

/// {@template amplify_auth_cognito.legacy_credential_store_data_extension}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform
as io;
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/model/hosted_ui/oauth_parameters.dart';
// ignore: implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/event/hosted_ui_event.dart';
// ignore: implementation_imports, invalid_use_of_internal_member
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:flutter/services.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'dart:io';
import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart';
// ignore: invalid_use_of_internal_member,implementation_imports
import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart';
import 'package:amplify_auth_cognito_dart/src/state/state/credential_store_state.dart';
// ignore: invalid_use_of_internal_member,implementation_imports
import 'package:amplify_auth_cognito_dart/src/state/state.dart';
import 'package:amplify_auth_cognito_test/amplify_auth_cognito_test.dart';
import 'package:amplify_auth_cognito_test/hosted_ui/hosted_ui_common.dart';
import 'package:amplify_core/amplify_core.dart';
Expand Down
Loading
Loading