Skip to content

Commit

Permalink
chore(api)!: Removed deprecated members … (#4772)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed Apr 25, 2024
1 parent 9f53cd1 commit 01fa753
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class GraphQLRequest<T> with AWSSerializable<Map<String, Object?>> {
/// See https://docs.amplify.aws/lib/graphqlapi/advanced-workflows/q/platform/flutter/.
final ModelType? modelType;

@Deprecated('Use toJson instead')
Map<String, dynamic> serializeAsMap() => toJson();

@override
Map<String, Object?> toJson() => {
'id': id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

part of '../amplify_exception.dart';

@Deprecated('Use HttpStatusException instead')
typedef RestException = HttpStatusException;

/// {@template amplify_core.api.http_status_exception}
/// An HTTP error encountered during a REST API call, i.e. for calls returning
/// non-2xx status codes.
Expand Down
1 change: 0 additions & 1 deletion packages/amplify_core/lib/src/types/query/query_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
library query_field;

import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_core/src/types/temporal/datetime_parse.dart';

part 'query_field_operators.dart';
part 'query_pagination.dart';
Expand Down
111 changes: 1 addition & 110 deletions packages/amplify_core/lib/src/types/query/query_field_operators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ abstract class QueryFieldOperator<T> {
/// where [other] is a field on the model.
bool evaluate(T? other);

/// Similar to `evaluate`, except `other` should be the
/// *serialized* value of a field on the model.
///
/// This should be used to support comparisons with models
/// that were generated prior to `toMap()` being added.
// TODO(Jordan-Nelson): remove at next major version bump
@Deprecated('Regenerate models with latest CLI and use `evaluate` instead.')
bool evaluateSerialized(T? other);

Map<String, dynamic> serializeAsMap();

Map<String, dynamic> serializeAsMapWithOperator(
Expand All @@ -55,16 +46,7 @@ abstract class QueryFieldOperator<T> {

/// check the type of [value] and invoke corresponding serialize method
dynamic serializeDynamicValue(dynamic value) {
// DateTime is deprecated and will be removed in the next major version
if (value is DateTime) {
if (zDebugMode) {
safePrint(
'WARNING: Using DateTime types in a QueryPredicate is deprecated. '
'Use a Temporal Date/Time Type instead.',
);
}
return value.toDateTimeIso8601String();
} else if (value is TemporalDate) {
if (value is TemporalDate) {
return value.format();
} else if (value is TemporalDateTime) {
return value.format();
Expand Down Expand Up @@ -110,18 +92,6 @@ class EqualQueryOperator<T> extends QueryFieldOperatorSingleValue<T> {

return value == other;
}

@override
bool evaluateSerialized(T? other) {
// if `other` is a Map and has an "id" field, the query predicate is on a
// nested model, such as `Post.BLOG.eq(myBlog.modelIdentifier))`,
// and the value should be compared against the model ID.
if (other is Map && other['id'] != null && value is String) {
return value == other['id'];
}
final serializedValue = serializeDynamicValue(value);
return other == serializedValue;
}
}

class EqualModelIdentifierQueryOperator<T extends ModelIdentifier>
Expand All @@ -134,13 +104,6 @@ class EqualModelIdentifierQueryOperator<T extends ModelIdentifier>
return other == value;
}

@override
bool evaluateSerialized(T? other) {
throw UnimplementedError(
'evaluateSerialized is not implemented for EqualModelIdentifierQueryOperator',
);
}

@override
Map<String, dynamic> serializeAsMap() {
return serializeAsMapWithOperator(type.toShortString(), value);
Expand All @@ -161,18 +124,6 @@ class NotEqualQueryOperator<T> extends QueryFieldOperatorSingleValue<T> {
}
return other != value;
}

@override
bool evaluateSerialized(T? other) {
// if `other` is a Map and has an "id" field, the query predicate is on a
// nested model, such as `Post.BLOG.eq(myBlog.modelIdentifier))`,
// and the value should be compared against the model ID.
if (other is Map && other['id'] != null && value is String) {
return value != other['id'];
}
final serializedValue = serializeDynamicValue(value);
return other != serializedValue;
}
}

class NotEqualModelIdentifierQueryOperator<T extends ModelIdentifier>
Expand All @@ -185,13 +136,6 @@ class NotEqualModelIdentifierQueryOperator<T extends ModelIdentifier>
return other != value;
}

@override
bool evaluateSerialized(T? other) {
throw UnimplementedError(
'evaluateSerialized is not implemented for NotEqualModelIdentifierQueryOperator',
);
}

@override
Map<String, dynamic> serializeAsMap() {
return serializeAsMapWithOperator(type.toShortString(), value);
Expand All @@ -210,15 +154,6 @@ class LessOrEqualQueryOperator<T extends Comparable<Object?>>
}
return other.compareTo(value) <= 0;
}

@override
bool evaluateSerialized(T? other) {
if (other == null) {
return false;
}
final serializedValue = serializeDynamicValue(value);
return other.compareTo(serializedValue) <= 0;
}
}

class LessThanQueryOperator<T extends Comparable<Object?>>
Expand All @@ -233,15 +168,6 @@ class LessThanQueryOperator<T extends Comparable<Object?>>
}
return other.compareTo(value) < 0;
}

@override
bool evaluateSerialized(T? other) {
if (other == null) {
return false;
}
final serializedValue = serializeDynamicValue(value);
return other.compareTo(serializedValue) < 0;
}
}

class GreaterOrEqualQueryOperator<T extends Comparable<Object?>>
Expand All @@ -256,15 +182,6 @@ class GreaterOrEqualQueryOperator<T extends Comparable<Object?>>
}
return other.compareTo(value) >= 0;
}

@override
bool evaluateSerialized(T? other) {
if (other == null) {
return false;
}
final serializedValue = serializeDynamicValue(value);
return other.compareTo(serializedValue) >= 0;
}
}

class GreaterThanQueryOperator<T extends Comparable<Object?>>
Expand All @@ -279,15 +196,6 @@ class GreaterThanQueryOperator<T extends Comparable<Object?>>
}
return other.compareTo(value) > 0;
}

@override
bool evaluateSerialized(T? other) {
if (other == null) {
return false;
}
final serializedValue = serializeDynamicValue(value);
return other.compareTo(serializedValue) > 0;
}
}

class ContainsQueryOperator extends QueryFieldOperatorSingleValue<String> {
Expand All @@ -309,9 +217,6 @@ class ContainsQueryOperator extends QueryFieldOperatorSingleValue<String> {
);
}
}

@override
bool evaluateSerialized(dynamic other) => evaluate(other);
}

class BetweenQueryOperator<T extends Comparable<Object?>>
Expand All @@ -330,17 +235,6 @@ class BetweenQueryOperator<T extends Comparable<Object?>>
return other.compareTo(start) >= 0 && other.compareTo(end) <= 0;
}

@override
bool evaluateSerialized(T? other) {
if (other == null) {
return false;
}
final serializedStart = serializeDynamicValue(start);
final serializedEnd = serializeDynamicValue(end);
return other.compareTo(serializedStart) >= 0 &&
other.compareTo(serializedEnd) <= 0;
}

@override
Map<String, dynamic> serializeAsMap() {
return <String, dynamic>{
Expand All @@ -362,7 +256,4 @@ class BeginsWithQueryOperator extends QueryFieldOperatorSingleValue<String> {
}
return other.startsWith(value);
}

@override
bool evaluateSerialized(String? other) => evaluate(other);
}
11 changes: 2 additions & 9 deletions packages/amplify_core/lib/src/types/query/query_predicate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ class QueryPredicateOperation extends QueryPredicate {
@override
bool evaluate(Model model) {
final fieldName = getFieldName(field);
// TODO(Jordan-Nelson): Remove try/catch at next major version bump
try {
final value = model.toMap()[fieldName];
return queryFieldOperator.evaluate(value);
} on UnimplementedError {
final value = model.toJson()[fieldName];
// ignore: deprecated_member_use_from_same_package
return queryFieldOperator.evaluateSerialized(value);
}
final value = model.toMap()[fieldName];
return queryFieldOperator.evaluate(value);
}

@override
Expand Down
Loading

0 comments on commit 01fa753

Please sign in to comment.