Skip to content

Commit

Permalink
give field rename its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Aug 27, 2024
1 parent 346de66 commit 4caa270
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:brick_build/src/annotation_finder.dart';
import 'package:brick_build/src/utils/string_helpers.dart';
import 'package:brick_core/field_serializable.dart';
import 'package:brick_core/field_rename.dart';

mixin AnnotationFinderWithFieldRename<Annotation extends Object> on AnnotationFinder<Annotation> {
/// Change serialization key based on the configuration.
Expand Down
16 changes: 16 additions & 0 deletions packages/brick_core/lib/field_rename.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// Values for the automatic field renaming behavior for class-level serializables.
///
/// Heavily borrowed/inspired by [JsonSerializable](https://github.com/dart-lang/json_serializable/blob/a581e5cc9ee25bf4ad61e8f825a311289ade905c/json_serializable/lib/src/json_key_utils.dart#L164-L179)
enum FieldRename {
/// Leave fields unchanged
none,

/// Encodes field name from `snakeCase` to `snake_case`.
snake,

/// Encodes field name from `kebabCase` to `kebab-case`.
kebab,

/// Capitalizes first letter of field name
pascal,
}
17 changes: 0 additions & 17 deletions packages/brick_core/lib/field_serializable.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
// ignore_for_file: constant_identifier_names

/// Values for the automatic field renaming behavior for [FieldSerializable].
///
/// Heavily borrowed/inspired by [JsonSerializable](https://github.com/dart-lang/json_serializable/blob/a581e5cc9ee25bf4ad61e8f825a311289ade905c/json_serializable/lib/src/json_key_utils.dart#L164-L179)
enum FieldRename {
/// Leave fields unchanged
none,

/// Encodes field name from `snakeCase` to `snake_case`.
snake,

/// Encodes field name from `kebabCase` to `kebab-case`.
kebab,

/// Capitalizes first letter of field name
pascal,
}

/// Interface for other field-level annotations.
/// For example, `class Rest extends FieldSerializable {}`
abstract class FieldSerializable {
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_graphql/lib/brick_graphql.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'package:brick_core/field_serializable.dart' show FieldRename;
export 'package:brick_core/field_rename.dart';
export 'package:brick_graphql/src/annotations/graphql.dart';
export 'package:brick_graphql/src/annotations/graphql_serializable.dart';
export 'package:brick_graphql/src/graphql_adapter.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:brick_core/core.dart';
import 'package:brick_core/field_serializable.dart';
import 'package:brick_core/field_rename.dart';
import 'package:brick_graphql/src/graphql_model.dart';
import 'package:brick_graphql/src/transformers/graphql_query_operation_transformer.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:brick_build/generators.dart' show ProviderSerializableGenerator, SerdesGenerator;
import 'package:brick_core/field_rename.dart';
import 'package:brick_graphql/brick_graphql.dart';
import 'package:brick_graphql_generators/src/graphql_deserialize.dart';
import 'package:brick_graphql_generators/src/graphql_fields.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/brick_graphql_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:
dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_build: ">=3.2.0 <4.0.0"
brick_core: ">=1.2.1 <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
@@ -1,4 +1,5 @@
import 'package:brick_graphql/brick_graphql.dart' show FieldRename, GraphqlSerializable;
import 'package:brick_core/field_rename.dart';
import 'package:brick_graphql/brick_graphql.dart' show GraphqlSerializable;
import 'package:brick_offline_first/brick_offline_first.dart';
import 'package:brick_offline_first_with_graphql/brick_offline_first_with_graphql.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:brick_core/field_rename.dart';
import 'package:brick_offline_first/brick_offline_first.dart';
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart';
import 'package:brick_rest/brick_rest.dart' show FieldRename, RestSerializable;
import 'package:brick_rest/brick_rest.dart' show RestSerializable;

final output = r'''
Future<RestConfigNoRename> _$RestConfigNoRenameFromRest(
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_rest/lib/brick_rest.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'package:brick_core/field_serializable.dart' show FieldRename;
export 'package:brick_core/field_rename.dart';
export 'package:brick_rest/rest_exception.dart';
export 'package:brick_rest/src/annotations/rest.dart';
export 'package:brick_rest/src/annotations/rest_serializable.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:brick_core/field_serializable.dart';
import 'package:brick_core/field_rename.dart';
import 'package:brick_core/query.dart';
import 'package:brick_rest/src/rest_model.dart';
import 'package:brick_rest/src/rest_request_transformer.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:brick_build/generators.dart';
import 'package:brick_rest/brick_rest.dart' show RestSerializable, FieldRename;
import 'package:brick_core/field_rename.dart';
import 'package:brick_rest/brick_rest.dart' show RestSerializable;
import 'package:brick_rest_generators/src/rest_deserialize.dart';
import 'package:brick_rest_generators/src/rest_fields.dart';
import 'package:brick_rest_generators/src/rest_serializable_extended.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_rest_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:
dependencies:
analyzer: ">=6.0.0 <7.0.0"
brick_build: ">=3.2.0 <4.0.0"
brick_core: ^1.1.1
brick_core: ">=1.2.1 <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

0 comments on commit 4caa270

Please sign in to comment.