-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eng(build): DRY recycled code to brick_build and brick_core (#419)
- Loading branch information
Showing
56 changed files
with
531 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/brick_build/lib/src/annotation_finder_with_field_rename.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:brick_build/src/annotation_finder.dart'; | ||
import 'package:brick_build/src/utils/string_helpers.dart'; | ||
import 'package:brick_core/field_rename.dart'; | ||
|
||
mixin AnnotationFinderWithFieldRename<Annotation extends Object> on AnnotationFinder<Annotation> { | ||
/// Change serialization key based on the configuration. | ||
/// `name` defined with a field annotation takes precedence. | ||
String renameField(String name, FieldRename? configValue, FieldRename defaultValue) { | ||
final renameTo = configValue ?? defaultValue; | ||
switch (renameTo) { | ||
case FieldRename.none: | ||
return name; | ||
case FieldRename.snake: | ||
return StringHelpers.snakeCase(name); | ||
|
||
/// Converts a camelized string to kebab-case | ||
/// Taken from [json_serializable](https://github.com/dart-lang/json_serializable/blob/d7e6612cf947e150710007a63b439f8f0c316d42/json_serializable/lib/src/utils.dart#L38-L47) | ||
case FieldRename.kebab: | ||
return name.replaceAllMapped(RegExp('[A-Z]'), (match) { | ||
var lower = match.group(0)!.toLowerCase(); | ||
|
||
if (match.start > 0) { | ||
lower = '-$lower'; | ||
} | ||
|
||
return lower; | ||
}); | ||
|
||
/// Capitalizes first letter | ||
/// Taken from [json_serializable](https://github.com/dart-lang/json_serializable/blob/d7e6612cf947e150710007a63b439f8f0c316d42/json_serializable/lib/src/utils.dart#L30-L36) | ||
case FieldRename.pascal: | ||
if (name.isEmpty) return ''; | ||
|
||
return name[0].toUpperCase() + name.substring(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,65 @@ | ||
## Unreleased | ||
|
||
## 1.2.1 | ||
|
||
- Add `FieldRename` to `FieldSerializable` | ||
|
||
## 1.2.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
- Apply standardized lints | ||
- Upgrade minimum Dart to 2.18 | ||
|
||
## 1.1.2 | ||
|
||
* Support Dart 3 | ||
* Loosen dependency restrictions to major versions | ||
- Support Dart 3 | ||
- Loosen dependency restrictions to major versions | ||
|
||
## 1.1.1 | ||
|
||
* Add `subscribe` to `QueryAction` | ||
- Add `subscribe` to `QueryAction` | ||
|
||
## 1.1.0 | ||
|
||
* Add Dart lints | ||
* Add `enumAsString` | ||
- Add Dart lints | ||
- Add `enumAsString` | ||
|
||
## 1.0.0+1 | ||
|
||
* Null safety cleanup and refactor | ||
- Null safety cleanup and refactor | ||
|
||
## 1.0.0 | ||
|
||
* Null safety | ||
* **BREAKING CHANGE**: because `required` is now a first-class Dart keyword, `required` in `WherePhrase`, `WhereCondition`, `And`, `Or`, and `Where` has been renamed to `isRequired`. | ||
* Add optional method `Provider#exists`. Whether a model instance is present. `null` is returned when existence is unknown. The model instance is not hydrated in the function output; a `bool` variant (e.g. `List<bool>`, `Map<_Model, bool>`) should be returned. | ||
- Null safety | ||
- **BREAKING CHANGE**: because `required` is now a first-class Dart keyword, `required` in `WherePhrase`, `WhereCondition`, `And`, `Or`, and `Where` has been renamed to `isRequired`. | ||
- Add optional method `Provider#exists`. Whether a model instance is present. `null` is returned when existence is unknown. The model instance is not hydrated in the function output; a `bool` variant (e.g. `List<bool>`, `Map<_Model, bool>`) should be returned. | ||
|
||
## 0.0.6 | ||
|
||
* Add a `doesNotContain` enum to `Compare` for `Where` queries | ||
- Add a `doesNotContain` enum to `Compare` for `Where` queries | ||
|
||
## 0.0.5 | ||
|
||
* Rename `Query#params` to `Query#providerArgs`, reflecting the much narrower purpose of the member | ||
- Rename `Query#params` to `Query#providerArgs`, reflecting the much narrower purpose of the member | ||
|
||
## 0.0.4 | ||
|
||
* `FieldSerializable#defaultValue` changes from `dynamic` to `String`. As this is injected directly into the adapter, it does not need to be dynamic and should better reflect its purpose. | ||
- `FieldSerializable#defaultValue` changes from `dynamic` to `String`. As this is injected directly into the adapter, it does not need to be dynamic and should better reflect its purpose. | ||
|
||
## 0.0.3+1 | ||
|
||
* Moves generator placeholders to `FieldSerializable` form `OfflineFirst` | ||
* Removes query validation that ensures all Where conditions have a non-null value | ||
- Moves generator placeholders to `FieldSerializable` form `OfflineFirst` | ||
- Removes query validation that ensures all Where conditions have a non-null value | ||
|
||
## 0.0.3 | ||
|
||
* Add `And` and `Or` `Where` subclasses | ||
* Removes Type argument from `Where` | ||
* Adds semantic methods to `Where` such as `isExactly` and | ||
* **BREAKING** Revise `Where` syntax. This removes the second positional argument in favor of using it in a semantic method. | ||
* Adds `Where.exact` factory to preserve previous, short syntax | ||
* Move query-related files to `src/query` and make them accessible from a barrel file in the lib root | ||
- Add `And` and `Or` `Where` subclasses | ||
- Removes Type argument from `Where` | ||
- Adds semantic methods to `Where` such as `isExactly` and | ||
- **BREAKING** Revise `Where` syntax. This removes the second positional argument in favor of using it in a semantic method. | ||
- Adds `Where.exact` factory to preserve previous, short syntax | ||
- Move query-related files to `src/query` and make them accessible from a barrel file in the lib root | ||
|
||
## 0.0.2 | ||
|
||
* Fix linter hints | ||
* Adds `initialize` method to `ModelRepository`. This is enforces a predictable, overridable method for sub classes | ||
- Fix linter hints | ||
- Adds `initialize` method to `ModelRepository`. This is enforces a predictable, overridable method for sub classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.