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

refactor(auth)!: Remove generic types #2804

Merged
merged 4 commits into from Apr 7, 2023
Merged

refactor(auth)!: Remove generic types #2804

merged 4 commits into from Apr 7, 2023

Conversation

dnys1
Copy link
Contributor

@dnys1 dnys1 commented Mar 31, 2023

Removes generic types from the category/plugin interface and from all data classes. This fixes JSON serialization issues and cleans up the API, preventing accidental misuse of types and making the source code more accessible for first and third-party developers.

In the past, generic types were necessary since plugin keys returned category wrappers over plugins. The category had to remain generic over any plugin and the plugin key carried the generic types to make the category wrapper statically resemble the plugin. Now that the category and plugin have the exact same interface and the plugin key directly returns the plugin, there is no need for generics.

Fixes JSON serialization issues and cleans up the API, preventing accidental misuse.
@dnys1 dnys1 requested a review from a team as a code owner March 31, 2023 00:53
@dnys1 dnys1 marked this pull request as draft March 31, 2023 14:51
In the past, generic types were necessary since plugin keys returned category wrappers over plugins. The category had to remain generic over any plugin and the plugin key carried the generic types to make the category wrapper statically resemble the plugin.

Now that the category and plugin have the exact same interface and the plugin key directly returns the plugin, there is no need for generics.
@dnys1 dnys1 changed the title chore(auth)!: Remove generic types from data classes chore(auth)!: Remove generic types Apr 3, 2023
@dnys1 dnys1 marked this pull request as ready for review April 3, 2023 16:25
@dnys1 dnys1 changed the title chore(auth)!: Remove generic types refactor(auth)!: Remove generic types Apr 3, 2023
@@ -16,17 +16,20 @@ import 'package:meta/meta.dart';
class CognitoUserAttributeKey extends AuthUserAttributeKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have Cognito types in core? I recommend moving the category level behaviors to AuthUserAttributeKey and those that are specific to Cognito out of core and into the Auth package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cognito configuration (and all plugin configurations) are in core and this is needed as part of it.

category level behaviors to AuthUserAttributeKey

This has already been done unless I missed something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is right, I pulled the PR and looked at the code in details. now I understand the structure and how config is done in core package.


@zAmplifyGenericSerializable
class AuthUser<Details extends SignInDetails>
abstract class AuthUser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to change to abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to match iOS/Android

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthUser is an interface in iOS and a final class in Android. I think it make sense to not change it to abstract because it is a data class with no behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a template for a data class given that plugins would extend it and override the SignInDetails type. I'm okay making it instantiable in this case.

@@ -15,7 +16,11 @@ abstract class AuthUserAttributeKey
with AWSSerializable<String>
implements Comparable<AuthUserAttributeKey> {
/// {@macro amplify_core.auth_user_attribute_key}
const AuthUserAttributeKey();
const factory AuthUserAttributeKey(String key) = _AuthUserAttributeKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the update here. Why add the factory constructor? I see it used in the converter, but you could use _AuthUserAttributeKey directly there, no?

Do we want to expose this for customers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - removed

const AuthUser({
required this.userId,
required this.username,
required this.signInDetails,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why are we changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are tradeoffs to having abstract types in data classes (SignInDetails). Generics are out. If this is included, a fromJson factory cannot be created since SignInDetails has no concrete type to call. I'll add it back to keep the signature the same and remove the fromJson factory.

@dnys1 dnys1 merged commit d4ab777 into next Apr 7, 2023
39 of 40 checks passed
@dnys1 dnys1 deleted the chore/next/json-todos branch April 7, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants