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

Add generator support for GenerateAdapters annotation #35

Merged
merged 112 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
44fed27
Almost there
Rexios80 Oct 18, 2024
65c688c
This is hard
Rexios80 Oct 18, 2024
5dfdcd1
Almost there
Rexios80 Oct 18, 2024
0fcfc14
What a mess
Rexios80 Oct 18, 2024
4680806
...
Rexios80 Oct 18, 2024
058bc7e
...
Rexios80 Oct 18, 2024
4f1ad99
...
Rexios80 Oct 18, 2024
17be7ae
...
Rexios80 Oct 18, 2024
071244f
...
Rexios80 Oct 18, 2024
0a567d4
...
Rexios80 Oct 18, 2024
aec65d2
...
Rexios80 Oct 18, 2024
e93e120
...
Rexios80 Oct 18, 2024
472aadb
Add special handling for ignored enum fields
Rexios80 Oct 19, 2024
5056d65
Ignore all fields on Object and Enum
Rexios80 Oct 19, 2024
92f9032
...
Rexios80 Oct 19, 2024
5714d48
...
Rexios80 Oct 19, 2024
c5e667d
...
Rexios80 Oct 19, 2024
2bbcc88
...
Rexios80 Oct 19, 2024
73b8863
Cleanup
Rexios80 Oct 19, 2024
66f07e1
Documentation
Rexios80 Oct 19, 2024
4ee5fda
Cleanup
Rexios80 Oct 19, 2024
7532405
Cleanup
Rexios80 Oct 19, 2024
196bcd8
...
Rexios80 Oct 19, 2024
fe83e39
...
Rexios80 Oct 19, 2024
b50676b
Working on documentation
Rexios80 Oct 19, 2024
1abfb3d
...
Rexios80 Oct 20, 2024
2a7f14e
...
Rexios80 Oct 20, 2024
d5eff44
Add migration guide
Rexios80 Oct 20, 2024
d84bdc6
...
Rexios80 Oct 20, 2024
f4fd915
Ignore static fields
Rexios80 Oct 20, 2024
4fb7c38
...
Rexios80 Oct 20, 2024
296592c
Switch to SharedPartBuilder for GenerateAdapters
Rexios80 Oct 20, 2024
aec3af8
Properly sort types
Rexios80 Oct 20, 2024
3fa9fd3
...
Rexios80 Oct 20, 2024
eeee9fe
Ignore getters without setters
Rexios80 Oct 20, 2024
a67fc17
Attempt 2 for this
Rexios80 Oct 20, 2024
a1eea4a
...
Rexios80 Oct 20, 2024
fc7f944
...
Rexios80 Oct 20, 2024
edebf3a
Only generate one id per field name
Rexios80 Oct 20, 2024
0b3be9f
Cleanup
Rexios80 Oct 21, 2024
abb0270
Working on documentation
Rexios80 Oct 21, 2024
64d676a
Convert example to GenerateAdapters
Rexios80 Oct 21, 2024
9d0176a
First test
Rexios80 Oct 21, 2024
e37d3f7
Initial tests
Rexios80 Oct 21, 2024
bd9ce0e
More tests
Rexios80 Oct 21, 2024
01d4b70
...
Rexios80 Oct 21, 2024
d89d73a
...
Rexios80 Oct 21, 2024
3bd8a00
Update references to old hive repo
Rexios80 Oct 21, 2024
1f123f0
...
Rexios80 Oct 21, 2024
fdddccb
Read hive_schema.yaml through the buildStep so changes affect builds
Rexios80 Oct 21, 2024
6a5a38e
...
Rexios80 Oct 21, 2024
a1cc280
Add codecov.yml
Rexios80 Oct 21, 2024
2a1e401
...
Rexios80 Oct 21, 2024
af4512d
Ignore constructors for coverage
Rexios80 Oct 21, 2024
ec6e8d7
Ignore non-static fields on enums
Rexios80 Oct 21, 2024
4c43e23
Schema validation
Rexios80 Oct 22, 2024
86ad76d
Place `hive_registrar.g.dart` with the `GenerateAdapters` annotation …
Rexios80 Oct 23, 2024
7a0792d
Add tests for registrar generation
Rexios80 Oct 23, 2024
1ceb434
Updating documentation
Rexios80 Oct 23, 2024
79b3150
Regenerate
Rexios80 Oct 23, 2024
e30faf7
Merge branch 'main' into feature/generate-adapters
Rexios80 Oct 23, 2024
6ca6bf5
Fix analysis in generated files
Rexios80 Oct 23, 2024
1f47cb8
...
Rexios80 Oct 23, 2024
62b0bd0
Do not run build_runner in hive_generator
Rexios80 Oct 23, 2024
0cea303
Add more details to registrar generation errors
Rexios80 Oct 25, 2024
64a3f7c
Fix tests
Rexios80 Oct 25, 2024
4ddce35
Sort uris in error for testing
Rexios80 Oct 25, 2024
9b8f093
Formatting
Rexios80 Oct 25, 2024
04c5cc3
Update grammar
Rexios80 Oct 25, 2024
bf2ef97
Respect configured ignores in registrar builder
Rexios80 Oct 28, 2024
90691c4
Merge branch 'main' into feature/generate-adapters
Rexios80 Oct 28, 2024
a43c060
Use correct version
Rexios80 Oct 28, 2024
bf2f873
...
Rexios80 Oct 28, 2024
cf18879
Regenerate mocks
Rexios80 Oct 28, 2024
d895cbb
Rename file
Rexios80 Oct 29, 2024
faeca12
Merge remote-tracking branch 'origin/main' into feature/generate-adap…
Rexios80 Oct 29, 2024
66e3345
Merge branch 'main' into feature/generate-adapters
Rexios80 Nov 1, 2024
055ce88
Update readme
Rexios80 Nov 1, 2024
2f56899
Merge branch 'main' into feature/generate-adapters
Rexios80 Nov 5, 2024
f30b1b7
Refactoring
Rexios80 Nov 5, 2024
6242699
...
Rexios80 Nov 5, 2024
5cd9ab7
Wrote the migrator
Rexios80 Nov 5, 2024
4e6bb8c
Testing works
Rexios80 Nov 5, 2024
5f415aa
...
Rexios80 Nov 5, 2024
a27e50f
Update readme
Rexios80 Nov 5, 2024
8893735
...
Rexios80 Nov 5, 2024
26381be
...
Rexios80 Nov 5, 2024
bc92b1a
...
Rexios80 Nov 5, 2024
d59a424
...
Rexios80 Nov 5, 2024
1f91041
...
Rexios80 Nov 5, 2024
53e3a7d
Sanitize field names
Rexios80 Nov 5, 2024
5078064
Update migration guide
Rexios80 Nov 6, 2024
c726879
Better error handling for migration tool
Rexios80 Nov 7, 2024
d658041
...
Rexios80 Nov 7, 2024
b97f6c7
...
Rexios80 Nov 7, 2024
1b2040f
...
Rexios80 Nov 7, 2024
3fbbb11
Update tests
Rexios80 Nov 7, 2024
ba5e9dc
Fix enum handling
Rexios80 Nov 7, 2024
568459b
Fix typo
Rexios80 Nov 7, 2024
5a3294a
Handle multiple GenerateAdapters on same element
Rexios80 Nov 7, 2024
e88bd1d
...
Rexios80 Nov 7, 2024
0cf8773
...
Rexios80 Nov 7, 2024
f2e7119
...
Rexios80 Nov 7, 2024
22d98aa
Generate hive_adapters.dart during migration
Rexios80 Nov 12, 2024
1c0ad8c
Force write as string so migrated files don't get deleted on next build
Rexios80 Nov 12, 2024
50afc8a
Handle possible schema mismatches in migration tool
Rexios80 Nov 13, 2024
5d58b64
Fix issue with setter names
Rexios80 Nov 13, 2024
4f06756
Fix error output
Rexios80 Nov 13, 2024
3b321f5
Merge branch 'feature/generate-adapters-annotation' into feature/gene…
Rexios80 Nov 13, 2024
f72bb88
Revert example dependency override
Rexios80 Nov 13, 2024
65bf44c
Merge branch 'main' into feature/generate-adapters
Rexios80 Nov 19, 2024
d58565b
Remove dependency override
Rexios80 Nov 19, 2024
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
Prev Previous commit
Next Next commit
Sanitize field names
Rexios80 committed Nov 5, 2024

Verified

This commit was signed with the committer’s verified signature.
Rexios80 Rexios
commit 53e3a7df858af31487d99fdcbd366212557c7904
16 changes: 14 additions & 2 deletions hive_generator/lib/src/builder/schema_migrator_builder.dart
Original file line number Diff line number Diff line change
@@ -37,11 +37,23 @@ class SchemaMigratorBuilder implements Builder {

schemaTypes.add((cls.thisType.getDisplayString(), result.schema));
}

schemaTypes.sort((a, b) => a.$2.typeId.compareTo(b.$2.typeId));
final nextTypeId = schemaTypes.isEmpty ? 0 : schemaTypes.last.$2.typeId + 1;
final types = {for (final type in schemaTypes) type.$1: type.$2};

final sanitizedSchemaTypes = <(String, HiveSchemaType)>[];
// Sanitize field names
for (final type in schemaTypes) {
final sanitizedFields = <String, HiveSchemaField>{};
for (final MapEntry(:key, :value) in type.$2.fields.entries) {
// Make field names public
final sanitizedKey = key.startsWith('_') ? key.substring(1) : key;
sanitizedFields[sanitizedKey] = value;
}
sanitizedSchemaTypes
.add((type.$1, type.$2.copyWith(fields: sanitizedFields)));
}

final types = {for (final type in sanitizedSchemaTypes) type.$1: type.$2};
await buildStep.writeAsString(
buildStep.asset('lib/hive_schema.g.yaml'),
HiveSchema(nextTypeId: nextTypeId, types: types).toString(),
13 changes: 13 additions & 0 deletions hive_generator/lib/src/model/hive_schema.dart
Original file line number Diff line number Diff line change
@@ -62,6 +62,19 @@ class HiveSchemaType {

/// To json
Map<String, dynamic> toJson() => _$HiveSchemaTypeToJson(this);

/// Copy with
HiveSchemaType copyWith({
int? typeId,
int? nextIndex,
Map<String, HiveSchemaField>? fields,
}) {
return HiveSchemaType(
typeId: typeId ?? this.typeId,
nextIndex: nextIndex ?? this.nextIndex,
fields: fields ?? this.fields,
);
}
}

/// Information about a Hive adapter field
19 changes: 16 additions & 3 deletions hive_generator/test/schema_migrator_test.dart
Original file line number Diff line number Diff line change
@@ -24,7 +24,18 @@ class Class2 {
import 'package:hive_ce/hive.dart';

@HiveType(typeId: 3)
class Class3 {}
class Class3 {
Class3({required double value}): _value = value;

@HiveField(0)
double _value;

double get value => _value;

set value(double value) {
_value = value;
}
}
''',
};

@@ -74,8 +85,10 @@ types:
fields: {}
Class3:
typeId: 3
nextIndex: 0
fields: {}
nextIndex: 1
fields:
value:
index: 0
''',
},
);