Skip to content

Commit

Permalink
eng: deprecate FieldSerializable#nullable #520
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Jan 2, 2025
1 parent fe0c05b commit 3fbc810
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 46 deletions.
1 change: 0 additions & 1 deletion docs/data/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ As providers are ultimately responsible for converting raw data into model data,
| `ignore:` | Do not deserialize (from) or serialize (to) this field to a provider | `@Rest(ignore: true)` |
| `name:` | Stored key for this field according to the provider. In SQLite, for example, this would be the column name. | `@Sqlite(name: "address_2")` |
| `defaultValue:` | Value to use in absence or `null` of the instance. It does not dictate what the Dart model will hold on empty instantiation. **Recommended to use Dart's default constructor assignment instead**. | `@Rest(defaultValue: '[]')` |
| `nullable:` | `null` fields are handled gracefully when serializing and deserializing. | `@Rest(nullable: true)` |
| `fromGenerator` | A stringified function with access to [placeholders](#placeholders); replaces adapter's generated deserialize code for the field. Do not include trailing semicolons or function body wrapping symbols (`{}` or `=>`) in the definition. | `@Rest(fromGenerator: "int.tryParse(%DATA_PROPERTY%.toString())")` |
| `toGenerator` | A stringified function with access to [placeholders](#placeholders); replaces adapter's generated serialize code for the field. Do not include trailing semicolons or function body wrapping symbols (`{}` or `=>`) in the definition. | `@Sqlite(toGenerator: "%INSTANCE_PROPERTY% > 1 ? 1 : 0")` |

Expand Down
5 changes: 5 additions & 0 deletions packages/brick_build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

## 3.3.1

- Remove `FieldSerializable#nullable` requirement on `deserializerNullableClause`
- Update minimum `brick_core` to `1.4.0`

## 3.3.0

- Add documentation to increase pub.dev score
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_build/example/file_fields.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:brick_core/field_serializable.dart';
import 'package:brick_build/generators.dart';
import 'package:brick_core/field_serializable.dart';

// in a real-world equivalent, this is an annotation
class File implements FieldSerializable {
Expand Down Expand Up @@ -52,7 +52,7 @@ class _FileSerdesFinder extends AnnotationFinder<File> {
_FileSerdesFinder();

@override
File from(element) {
File from(FieldElement element) {
final obj = objectForField(element);

if (obj == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_build/lib/src/serdes_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ abstract class SerdesGenerator<FieldAnnotation extends FieldSerializable,
required FieldAnnotation fieldAnnotation,
required String name,
}) =>
fieldAnnotation.nullable && field.type.nullabilitySuffix != NullabilitySuffix.none
field.type.nullabilitySuffix != NullabilitySuffix.none
? "data['$name'] == null ? null :"
: '';

Expand Down
4 changes: 2 additions & 2 deletions packages/brick_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_build
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.3.0
version: 3.3.1

environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_core: ^1.3.0
brick_core: ">=1.4.0 <2.0.0"
build: ^2.3.0
dart_style: ">=2.0.0 <3.0.0"
glob: ">=2.1.0 <3.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 1.4.0

- **DEPRECATION** remove `FieldSerializable#nullable`. Builders should evaluate the nullable suffix of the field instead

## 1.3.1

- `const`antize `Where.exactly` and `OrderBy.{desc|asc}`
Expand Down
1 change: 1 addition & 0 deletions packages/brick_core/lib/field_serializable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class FieldSerializable {

/// When `true`, `null` fields are handled gracefully when serializing and deserializing.
/// For Dart >=2.12, the member type must also be nullable (i.e. `bool?`).
@Deprecated('Use a nullable type instead')
bool get nullable;

/// Manipulates output for the field in the serialize generator.
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_core/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_core
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 1.3.1
version: 1.4.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 3.3.0

- **DEPRECATION** remove `Graphql#nullable`. Builders should evaluate the nullable suffix of the field instead

## 3.2.0

- **DEPRECATION** `Query(providerArgs: {'context':})` is now `Query(forProviders: [GraphqlProviderQuery(context:)])`
Expand Down
3 changes: 2 additions & 1 deletion packages/brick_graphql/lib/src/annotations/graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Graphql implements FieldSerializable {
/// This indicates that the payload from GraphQL could be `null` and is not related to
/// Dart nullability. Defaults to `false`.
@override
@Deprecated('Use a nullable type instead')
final bool nullable;

/// Supply subfields that should be requested from the server.
Expand All @@ -58,7 +59,7 @@ class Graphql implements FieldSerializable {
bool? ignoreFrom,
bool? ignoreTo,
this.name,
bool? nullable,
@Deprecated('Use a nullable type instead') bool? nullable,
this.subfields,
this.toGenerator,
}) : enumAsString = enumAsString ?? false,
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_graphql/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_graphql
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.2.0
version: 3.3.0

environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
brick_core: ^1.3.0
brick_core: ">=1.4.0 <2.0.0"
collection: ">=1.15.0 <2.0.0"
gql: ">=0.13.0 <2.0.0"
gql_exec: ">=0.3.0 <2.0.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/brick_graphql_generators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Unreleased

## 3.3.1

- Upgrade `brick_core` to `1.4.0`
- Upgrade `brick_build` to `3.3.1`
- Ignore `Graphql#nullable`

## 3.3.0

- Upgrade `brick_core` to `1.3.0`
Expand Down
2 changes: 0 additions & 2 deletions packages/brick_graphql_generators/lib/src/graphql_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class GraphqlAnnotationFinder extends AnnotationFinder<Graphql>
config?.fieldRename,
GraphqlSerializable.defaults.fieldRename,
),
nullable: Graphql.defaults.nullable,
enumAsString: Graphql.defaults.enumAsString,
);
}
Expand All @@ -43,7 +42,6 @@ class GraphqlAnnotationFinder extends AnnotationFinder<Graphql>
ignoreTo: obj.getField('ignoreTo')?.toBoolValue() ?? Graphql.defaults.ignoreTo,
name: obj.getField('name')?.toStringValue() ??
renameField(element.name, config?.fieldRename, GraphqlSerializable.defaults.fieldRename),
nullable: obj.getField('nullable')?.toBoolValue() ?? Graphql.defaults.nullable,
subfields: _convertMapToMap(obj.getField('subfields')?.toMapValue()),
toGenerator: obj.getField('toGenerator')!.toStringValue(),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/brick_graphql_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_graphql_g
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.3.0
version: 3.3.1

environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_build: ">=3.2.0 <4.0.0"
brick_core: ">=1.3.0 <2.0.0"
brick_build: ">=3.3.1 <4.0.0"
brick_core: ">=1.4.0 <2.0.0"
brick_graphql: ">=3.0.0 <4.0.0"
brick_json_generators: ">=3.0.0 <4.0.0"
build: ">=2.0.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EnumAsString {
@Graphql(enumAsString: true)
final Hat hat;

@Graphql(enumAsString: true, nullable: true)
@Graphql(enumAsString: true)
final Hat? nullableHat;

@Graphql(enumAsString: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'package:brick_core/core.dart';
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart';
import 'package:brick_offline_first/brick_offline_first.dart';
import 'package:brick_rest/brick_rest.dart';
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart';
import 'package:brick_offline_first_with_rest_example/brick/models/hat.dart';
import 'package:brick_offline_first_with_rest_example/brick/models/mounty.model.dart';
import 'package:brick_rest/brick_rest.dart';
import 'package:brick_sqlite/brick_sqlite.dart';

class KitchenSinkRequest extends RestRequestTransformer {
final get = RestRequest(url: '/my-path', topLevelKey: 'kitchen_sinks');
@override
final get = const RestRequest(url: '/my-path', topLevelKey: 'kitchen_sinks');

final upsert = RestRequest(url: '/my-path', topLevelKey: 'kitchen_sink');
@override
final upsert = const RestRequest(url: '/my-path', topLevelKey: 'kitchen_sink');

KitchenSinkRequest(Query? query, Model? instance) : super(query, instance);
KitchenSinkRequest(super.query, super.instance);
}

@ConnectOfflineFirstWithRest(
Expand Down Expand Up @@ -58,7 +60,6 @@ class KitchenSink extends OfflineFirstWithRestModel {
@Rest(defaultValue: "'a default value'")
final String? restAnnotationDefaultValue;

@Rest(nullable: true)
final String? restAnnotationNullable;

@Rest(ignore: true)
Expand All @@ -79,7 +80,6 @@ class KitchenSink extends OfflineFirstWithRestModel {
@Rest(enumAsString: true)
final AnyEnum? enumFromString;

@Sqlite(nullable: true)
final String? sqliteAnnotationNullable;

@Sqlite(defaultValue: "'default value'")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// ignore_for_file: always_use_package_imports

import 'package:brick_offline_first/brick_offline_first.dart';
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
import 'package:brick_offline_first_with_supabase_example/models/mounty.model.dart';
import 'package:brick_sqlite/brick_sqlite.dart';
import 'package:brick_supabase/brick_supabase.dart';

import 'hat.dart';
import 'mounty.model.dart';

@ConnectOfflineFirstWithSupabase()
class KitchenSink extends OfflineFirstWithSupabaseModel {
final String? anyString;
Expand Down Expand Up @@ -44,7 +48,6 @@ class KitchenSink extends OfflineFirstWithSupabaseModel {
@Supabase(defaultValue: "'a default value'")
final String? restAnnotationDefaultValue;

@Supabase(nullable: true)
final String? restAnnotationNullable;

@Supabase(ignore: true)
Expand All @@ -65,7 +68,6 @@ class KitchenSink extends OfflineFirstWithSupabaseModel {
@Supabase(enumAsString: true)
final AnyEnum? enumFromString;

@Sqlite(nullable: true)
final String? sqliteAnnotationNullable;

@Sqlite(defaultValue: "'default value'")
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 3.2.0

- **DEPRECATION** remove `Rest#nullable`. Builders should evaluate the nullable suffix of the field instead

## 3.1.0

- **DEPRECATION** `Query(providerArgs: {'request':})` is now `Query(forProviders: [RestProviderQuery(request:)])`.
Expand Down
3 changes: 2 additions & 1 deletion packages/brick_rest/lib/src/annotations/rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Rest implements FieldSerializable {
/// This indicates that the payload from REST could be `null` and is not related to
/// Dart nullability. Defaults to `false`.
@override
@Deprecated('Use a nullable type instead')
final bool nullable;

@override
Expand All @@ -60,7 +61,7 @@ class Rest implements FieldSerializable {
bool? ignoreFrom,
bool? ignoreTo,
this.name,
bool? nullable,
@Deprecated('Use a nullable type instead') bool? nullable,
this.toGenerator,
}) : enumAsString = enumAsString ?? false,
ignore = ignore ?? false,
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_rest/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_rest
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.1.0
version: 3.2.0

environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
brick_core: ^1.3.0
brick_core: ">=1.4.0 <2.0.0"
http: ">=1.0.0 <2.0.0"
logging: ">=1.0.0 <2.0.0"
meta: ">=1.3.0 <2.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_rest_generators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 3.3.1

- Upgrade `brick_core` to `1.4.0`

## 3.3.0

- Upgrade `brick_core` to `1.3.0`
Expand Down
3 changes: 0 additions & 3 deletions packages/brick_rest_generators/lib/src/rest_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class RestAnnotationFinder extends AnnotationFinder<Rest>
config?.fieldRename,
RestSerializable.defaults.fieldRename,
),
nullable: config?.nullable ?? Rest.defaults.nullable,
enumAsString: Rest.defaults.enumAsString,
);
}
Expand All @@ -42,8 +41,6 @@ class RestAnnotationFinder extends AnnotationFinder<Rest>
ignoreTo: obj.getField('ignoreTo')!.toBoolValue() ?? Rest.defaults.ignoreTo,
name: obj.getField('name')!.toStringValue() ??
renameField(element.name, config?.fieldRename, RestSerializable.defaults.fieldRename),
nullable:
obj.getField('nullable')!.toBoolValue() ?? config?.nullable ?? Rest.defaults.nullable,
toGenerator: obj.getField('toGenerator')!.toStringValue(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_rest_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_rest_gene
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.3.0
version: 3.3.1

environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_build: ">=3.2.0 <4.0.0"
brick_core: ">=1.3.0 <2.0.0"
brick_core: ">=1.4.0 <2.0.0"
brick_json_generators: ">=3.0.0 <4.0.0"
brick_rest: ">=3.0.4 <4.0.0"
build: ">=2.0.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class EnumAsString {
@Rest(enumAsString: true)
final Hat hat;

@Rest(enumAsString: true, nullable: true)
@Rest(enumAsString: true)
final Hat? nullableHat;

@Rest(enumAsString: true)
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_supabase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 1.3.0

- **DEPRECATION** remove `Supabase#nullable`. Builders should evaluate the nullable suffix of the field instead

## 1.2.0

- **DEPRECATION** `Query(providerArgs: {'limitReferencedTable':})` has been removed in favor of `Query(limitBy:)`
Expand Down
3 changes: 2 additions & 1 deletion packages/brick_supabase/lib/src/annotations/supabase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Supabase implements FieldSerializable {
/// This indicates that the payload from Supabase could be `null` and is not related to
/// Dart nullability. Defaults to `false`.
@override
@Deprecated('Use a nullable type instead')
final bool nullable;

@override
Expand All @@ -102,7 +103,7 @@ class Supabase implements FieldSerializable {
this.query,
bool? unique,
this.name,
bool? nullable,
@Deprecated('Use a nullable type instead') bool? nullable,
this.toGenerator,
}) : enumAsString = enumAsString ?? false,
ignore = ignore ?? false,
Expand Down
Loading

0 comments on commit 3fbc810

Please sign in to comment.