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

fix: test fixes for offline builders after nullable deprecation #522

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion packages/brick_json_generators/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.
- Upgrade `brick_core` to `1.4.0`
- Update analysis to modern lints
- Remove redundant nullability checks for siblings and iterable siblings
- Remove redundant nullability checks for enums, siblings and iterable siblings

## 3.1.1

Expand Down
2 changes: 1 addition & 1 deletion packages/brick_json_generators/lib/json_deserialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mixin JsonDeserialize<TModel extends Model, Annotation extends FieldSerializable
} else if (checker.isEnum) {
final deserializeFactory = checker.enumDeserializeFactory(providerName);
if (deserializeFactory != null) {
return '${checker.isNullable ? "$fieldValue == null ? null :" : ""} ${SharedChecker.withoutNullability(field.type)}.$deserializeFactory($fieldValue)';
return '${SharedChecker.withoutNullability(field.type)}.$deserializeFactory($fieldValue)';
}

if (fieldAnnotation.enumAsString) {
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_json_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_json_gene
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.2.0
version: 3.2.0+1

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/brick_offline_first_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ environment:

dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_build: ">=3.0.0 <4.0.0"
brick_core: ^1.3.0
brick_json_generators: ">=3.0.0 <4.0.0"
brick_build: ">=3.3.1 <4.0.0"
brick_core: ">=1.4.0 <4.0.0"
brick_json_generators: ">=3.2.0 <4.0.0"
brick_offline_first: ">=3.0.0 <4.0.0"
brick_sqlite: ">=3.0.0 <4.0.0"
brick_sqlite_generators: ">=3.1.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ Future<CustomOfflineFirstSerdes> _$CustomOfflineFirstSerdesFromTest(
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return CustomOfflineFirstSerdes(
string: Serializable.fromTest(data['string']),
string:
data['string'] == null ? null : Serializable.fromTest(data['string']),
constructorFieldNullabilityMismatch:
data['constructor_field_nullability_mismatch'] as bool?,
strings: data['strings']
?.map((c) => Serializable.fromTest(c as Map<String, dynamic>))
.toList()
.cast<Serializable>());
strings: data['strings'] == null
? null
: data['strings']
?.map((c) => Serializable.fromTest(c as Map<String, dynamic>))
.toList()
.cast<Serializable>());
}

Future<Map<String, dynamic>> _$CustomOfflineFirstSerdesToTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const output = r'''
Future<DefaultValue> _$DefaultValueFromTest(Map<String, dynamic> data,
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return DefaultValue(string: data['string'] as String? ?? "Thomas");
return DefaultValue(
string: data['string'] == null
? null
: data['string'] as String? ?? "Thomas");
}

Future<Map<String, dynamic>> _$DefaultValueToTest(DefaultValue instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Future<Futures> _$FuturesFromTest(Map<String, dynamic> data,
return Futures(
string: data['string'] as Future<String>,
strings: data['strings'].toList().cast<Future<String>>(),
futureStrings: data['future_strings']?.toList().cast<String>(),
futureStrings: data['future_strings'] == null
? null
: data['future_strings']?.toList().cast<String>(),
assoc: AssocAdapter()
.fromTest(data['assoc'], provider: provider, repository: repository),
assocs: Future.wait<Assoc>(data['assocs']
Expand All @@ -20,11 +22,13 @@ Future<Futures> _$FuturesFromTest(Map<String, dynamic> data,
.toList()
.cast<Future<Assoc>>() ??
[]),
futureAssocs: data['future_assocs']
?.map((d) => AssocAdapter()
.fromTest(d, provider: provider, repository: repository))
.toList()
.cast<Future<Assoc>>());
futureAssocs: data['future_assocs'] == null
? null
: data['future_assocs']
?.map((d) => AssocAdapter()
.fromTest(d, provider: provider, repository: repository))
.toList()
.cast<Future<Assoc>>());
}

Future<Map<String, dynamic>> _$FuturesToTest(Futures instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ Future<NullableField> _$NullableFieldFromTest(Map<String, dynamic> data,
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return NullableField(
restFalse: data['rest_false'] as String?,
nullableRestTrue: data['nullable_rest_true'] as String?,
restFalse:
data['rest_false'] == null ? null : data['rest_false'] as String?,
nullableRestTrue: data['nullable_rest_true'] == null
? null
: data['nullable_rest_true'] as String?,
restTrue: data['rest_true'] as String,
sqliteFalse: data['sqlite_false'] as String?,
sqliteTrue: data['sqlite_true'] as String?,
sqliteFalse:
data['sqlite_false'] == null ? null : data['sqlite_false'] as String?,
sqliteTrue:
data['sqlite_true'] == null ? null : data['sqlite_true'] as String?,
constructorFieldNullabilityMismatch:
data['constructor_field_nullability_mismatch'] as String?,
constructorFieldTypeMismatch:
Expand All @@ -37,11 +42,16 @@ Future<NullableField> _$NullableFieldFromSqlite(Map<String, dynamic> data,
{required SqliteProvider provider,
OfflineFirstRepository? repository}) async {
return NullableField(
restFalse: data['rest_false'] as String?,
nullableRestTrue: data['nullable_rest_true'] as String?,
restFalse:
data['rest_false'] == null ? null : data['rest_false'] as String?,
nullableRestTrue: data['nullable_rest_true'] == null
? null
: data['nullable_rest_true'] as String?,
restTrue: data['rest_true'] as String,
sqliteFalse: data['sqlite_false'] as String?,
sqliteTrue: data['sqlite_true'] as String?,
sqliteFalse:
data['sqlite_false'] == null ? null : data['sqlite_false'] as String?,
sqliteTrue:
data['sqlite_true'] == null ? null : data['sqlite_true'] as String?,
constructorFieldNullabilityMismatch:
data['constructor_field_nullability_mismatch'] as String,
constructorFieldTypeMismatch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Future<OfflineFirstWhere> _$OfflineFirstWhereFromTest(Map<String, dynamic> data,
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return OfflineFirstWhere(
applied: await repository
?.getAssociation<Assoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r?.isNotEmpty ?? false ? r!.first : null),
applied: data['applied'] == null
? null
: await repository
?.getAssociation<Assoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r?.isNotEmpty ?? false ? r!.first : null),
notApplied: data['not_applied'] == null
? null
: await OtherAssocAdapter().fromTest(data['not_applied'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ Future<OfflineFirstWhere> _$OfflineFirstWhereFromTest(Map<String, dynamic> data,
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return OfflineFirstWhere(
assoc: repository!
.getAssociation<OtherAssoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r!.first),
assocs: (data['assocs'] ?? [])
.map<Future<Assoc>>((s) =>
repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then(
assoc: data['assoc'] == null
? null
: repository!
.getAssociation<OtherAssoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r!.first),
assocs: data['assocs'] == null
? null
: (data['assocs'] ?? [])
.map<Future<Assoc>>((s) => repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then(
(r) => r!.first))
.toList(),
loadedAssoc: await repository
.getAssociation<Assoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r?.isNotEmpty ?? false ? r!.first : null),
loadedAssocs: (await Future.wait<Assoc?>((data['loaded_assocs'] ?? []).map<Future<Assoc?>>((s) => repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s)])).then((r) => r?.isNotEmpty ?? false ? r!.first : null))))
.whereType<Assoc>()
.toList(),
multiLookupCustomGenerator: (data['multi_lookup_custom_generator'] ?? [])
.map<Future<Assoc>>((s) => repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then((r) => r!.first))
.toList());
.toList(),
loadedAssoc: data['loaded_assoc'] == null
? null
: await repository
.getAssociation<Assoc>(
Query(where: [Where.exact('id', data['id'])], limit: 1))
.then((r) => r?.isNotEmpty ?? false ? r!.first : null),
loadedAssocs: data['loaded_assocs'] == null
? null
: (await Future.wait<Assoc?>((data['loaded_assocs'] ?? []).map<Future<Assoc?>>((s) => repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s)])).then((r) => r?.isNotEmpty ?? false ? r!.first : null))))
.whereType<Assoc>()
.toList(),
multiLookupCustomGenerator: data['multi_lookup_custom_generator'] == null ? null : (data['multi_lookup_custom_generator'] ?? []).map<Future<Assoc>>((s) => repository.getAssociation<Assoc>(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then((r) => r!.first)).toList());
}

Future<Map<String, dynamic>> _$OfflineFirstWhereToTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ Future<OneToManyAssociation> _$OneToManyAssociationFromTest(
.toList()
.cast<Future<SqliteAssoc>>() ??
[]),
nullableAssoc: await Future.wait<SqliteAssoc>(data['nullable_assoc']
?.map((d) => SqliteAssocAdapter()
.fromTest(d, provider: provider, repository: repository))
.toList()
.cast<Future<SqliteAssoc>>() ??
[]));
nullableAssoc: data['nullable_assoc'] == null
? null
: await Future.wait<SqliteAssoc>(data['nullable_assoc']
?.map((d) => SqliteAssocAdapter()
.fromTest(d, provider: provider, repository: repository))
.toList()
.cast<Future<SqliteAssoc>>() ??
[]));
}

Future<Map<String, dynamic>> _$OneToManyAssociationToTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,44 @@ Future<PrimitiveFields> _$PrimitiveFieldsFromTest(Map<String, dynamic> data,
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return PrimitiveFields(
nullableInteger: data['nullable_integer'] as int?,
nullableBoolean: data['nullable_boolean'] as bool?,
nullableDub: data['nullable_dub'] as double?,
nullableString: data['nullable_string'] as String?,
nullableList: data['nullable_list']?.toList().cast<int>(),
nullableSet: data['nullable_set']?.toSet().cast<int>(),
nullableMap: data['nullable_map'],
nullableInteger: data['nullable_integer'] == null
? null
: data['nullable_integer'] as int?,
nullableBoolean: data['nullable_boolean'] == null
? null
: data['nullable_boolean'] as bool?,
nullableDub:
data['nullable_dub'] == null ? null : data['nullable_dub'] as double?,
nullableString: data['nullable_string'] == null
? null
: data['nullable_string'] as String?,
nullableList: data['nullable_list'] == null
? null
: data['nullable_list']?.toList().cast<int>(),
nullableSet: data['nullable_set'] == null
? null
: data['nullable_set']?.toSet().cast<int>(),
nullableMap: data['nullable_map'] == null ? null : data['nullable_map'],
nullableLongerCamelizedVariable:
data['nullable_longer_camelized_variable'] as String?,
nullableCasing: data['nullable_casing'] is int
? Casing.values[data['nullable_casing'] as int]
: null,
nullableListCasing: data['nullable_list_casing']
.map((e) => Casing.values[e])
.toList()
.cast<Casing>(),
data['nullable_longer_camelized_variable'] == null
? null
: data['nullable_longer_camelized_variable'] as String?,
nullableCasing: data['nullable_casing'] == null
? null
: data['nullable_casing'] is int
? Casing.values[data['nullable_casing'] as int]
: null,
nullableListCasing: data['nullable_list_casing'] == null
? null
: data['nullable_list_casing']
.map((e) => Casing.values[e])
.toList()
.cast<Casing>(),
nullableDateTime: data['nullable_date_time'] == null
? null
: DateTime.tryParse(data['nullable_date_time'] as String),
: data['nullable_date_time'] == null
? null
: DateTime.tryParse(data['nullable_date_time'] as String),
integer: data['integer'] as int,
boolean: data['boolean'] as bool,
dub: data['dub'] as double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Future<CustomOfflineFirstSerdes> _$CustomOfflineFirstSerdesFromTest(
{required TestProvider provider,
OfflineFirstRepository? repository}) async {
return CustomOfflineFirstSerdes(
string: Serializable.fromTest(data['string']));
string: data['string'] == null
? null
: Serializable.fromTest(data['string']));
}

Future<Map<String, dynamic>> _$CustomOfflineFirstSerdesToTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Future<CustomSerdes> _$CustomSerdesFromGraphql(Map<String, dynamic> data,
{required GraphqlProvider provider,
OfflineFirstRepository? repository}) async {
return CustomSerdes(
string: data['string'].split('').map((s) => '$s.1').join(''));
string: data['string'] == null
? null
: data['string'].split('').map((s) => '$s.1').join(''));
}

Future<Map<String, dynamic>> _$CustomSerdesToGraphql(CustomSerdes instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Future<SpecifyFieldName> _$SpecifyFieldNameFromGraphql(
Map<String, dynamic> data,
{required GraphqlProvider provider,
OfflineFirstRepository? repository}) async {
return SpecifyFieldName(email: data['email_address'] as String?);
return SpecifyFieldName(
email: data['email_address'] == null
? null
: data['email_address'] as String?);
}

Future<Map<String, dynamic>> _$SpecifyFieldNameToGraphql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Future<CustomSerdes> _$CustomSerdesFromRest(Map<String, dynamic> data,
{required RestProvider provider,
OfflineFirstRepository? repository}) async {
return CustomSerdes(
string: data['string'].split('').map((s) => '$s.1').join(''));
string: data['string'] == null
? null
: data['string'].split('').map((s) => '$s.1').join(''));
}

Future<Map<String, dynamic>> _$CustomSerdesToRest(CustomSerdes instance,
Expand Down
Loading
Loading