Skip to content

Commit

Permalink
check entity builders
Browse files Browse the repository at this point in the history
  • Loading branch information
j4qfrost committed Feb 22, 2024
1 parent a2b0b2b commit 0da2692
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ command:
usePubspecOverrides: true
scripts:
test-unit:
run: melos exec -c1 --fail-fast --ignore "*common*" --ignore "*application*" --ignore "*dependency*" -- "dart test -j1"
run: melos exec -c1 --fail-fast --ignore "*common*" --ignore "*application*" --ignore "*dependency*" -- "dart test"
select-pacakge:
no-private: true
test-with-coverage:
Expand All @@ -33,7 +33,7 @@ scripts:
select-pacakge:
no-private: true
cache-source-win:
run: melos exec -- "mkdir %PUB_CACHE%hosted\pub.dev\%MELOS_PACKAGE_NAME%-%MELOS_PACKAGE_VERSION% && xcopy %MELOS_PACKAGE_PATH% %PUB_CACHE%hosted\pub.dev\%MELOS_PACKAGE_NAME%-%MELOS_PACKAGE_VERSION% /Y /s /e"
run: melos exec -- "New-Item -ItemType Directory -Path %PUB_CACHE%hosted\pub.dev\%MELOS_PACKAGE_NAME%-%MELOS_PACKAGE_VERSION% -Force | Out-Null; Copy-Item -Path %MELOS_PACKAGE_PATH% -Destination %PUB_CACHE%hosted\pub.dev\%MELOS_PACKAGE_NAME%-%MELOS_PACKAGE_VERSION% -Recurse -Force"
select-pacakge:
no-private: true
hard-clean:
Expand Down
15 changes: 8 additions & 7 deletions packages/core/lib/src/runtime/orm/data_model_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ class DataModelCompiler {
.where(_isTypeManagedObjectSubclass)
.map((c) => c.reflectedType);

print(instanceTypes);
_builders = instanceTypes.map((t) => EntityBuilder(t)).toList();
for (final b in _builders!) {
for (final b in _builders) {
b.compile(_builders);
}
_validate();

for (final b in _builders!) {
b.link(_builders!.map((eb) => eb.entity).toList());
for (final b in _builders) {
b.link(_builders.map((eb) => eb.entity).toList());
m[b.entity.instanceType.toString()] = b.runtime;
}

return m;
}

List<EntityBuilder>? _builders;
late List<EntityBuilder> _builders;

void _validate() {
// Check for dupe tables
for (final builder in _builders!) {
final withSameName = _builders!
for (final builder in _builders) {
final withSameName = _builders
.where((eb) => eb.name == builder.name)
.map((eb) => eb.instanceTypeName)
.toList();
Expand All @@ -43,7 +44,7 @@ class DataModelCompiler {
}
}

for (final b in _builders!) {
for (final b in _builders) {
b.validate(_builders);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/src/runtime/orm/entity_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EntityBuilder {
String get tableDefinitionTypeName =>
MirrorSystem.getName(tableDefinitionType.simpleName);

void compile(List<EntityBuilder>? entityBuilders) {
void compile(List<EntityBuilder> entityBuilders) {
for (final p in properties) {
p.compile(entityBuilders);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/lib/src/runtime/orm/property_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PropertyBuilder {
DeleteRule? deleteRule;
List<ValidatorBuilder>? _validators;

void compile(List<EntityBuilder>? entityBuilders) {
void compile(List<EntityBuilder> entityBuilders) {
if (type == null) {
if (relate != null) {
relatedProperty =
Expand Down Expand Up @@ -287,10 +287,10 @@ class PropertyBuilder {
: name;
}

EntityBuilder _getRelatedEntityBuilderFrom(List<EntityBuilder>? builders) {
EntityBuilder _getRelatedEntityBuilderFrom(List<EntityBuilder> builders) {
final expectedInstanceType = getDeclarationType();
if (!relate!.isDeferred) {
return builders!.firstWhere(
return builders.firstWhere(
(b) => b.instanceType == expectedInstanceType,
orElse: () {
throw ManagedDataModelErrorImpl.noDestinationEntity(
Expand All @@ -302,7 +302,7 @@ class PropertyBuilder {
);
}

final possibleEntities = builders!.where((e) {
final possibleEntities = builders.where((e) {
return e.tableDefinitionType == expectedInstanceType ||
e.tableDefinitionType.isSubtypeOf(expectedInstanceType);
}).toList();
Expand Down

0 comments on commit 0da2692

Please sign in to comment.