From 8a4f33f2e336da52c0f66647cb430dd23c28b96e Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Fri, 10 May 2024 21:11:04 -0700 Subject: [PATCH] more null changes --- packages/core/lib/src/db/managed/entity.dart | 16 ++++----- packages/core/lib/src/db/managed/object.dart | 4 +-- .../src/db/managed/validation/metadata.dart | 2 +- packages/core/lib/src/db/query/mixin.dart | 4 +-- .../src/runtime/orm/data_model_compiler.dart | 18 ++-------- .../lib/src/runtime/orm/entity_builder.dart | 6 ++-- .../lib/src/runtime/orm/property_builder.dart | 18 +++++----- packages/core/lib/src/runtime/orm_impl.dart | 2 +- packages/core/test/db/data_model_test.dart | 4 +-- .../postgresql/test/tiered_where_test.dart | 36 +++++++++---------- 10 files changed, 49 insertions(+), 61 deletions(-) diff --git a/packages/core/lib/src/db/managed/entity.dart b/packages/core/lib/src/db/managed/entity.dart index ff9a46e2b..301d45788 100644 --- a/packages/core/lib/src/db/managed/entity.dart +++ b/packages/core/lib/src/db/managed/entity.dart @@ -68,7 +68,7 @@ class ManagedEntity implements APIComponentDocumenter { /// for [ManagedRelationshipType.hasMany] or [ManagedRelationshipType.hasOne] properties, as those values are derived by the foreign key reference /// on the inverse relationship property. /// Keys are the case-sensitive name of the relationship. - late Map relationships; + late Map relationships; /// All properties (relationships and attributes) of this entity. /// @@ -104,9 +104,9 @@ class ManagedEntity implements APIComponentDocumenter { /// set in their [Column] and all [ManagedRelationshipType.belongsTo] relationships. /// /// This list cannot be modified. - List? get defaultProperties { + List get defaultProperties { if (_defaultProperties == null) { - final elements = []; + final elements = []; elements.addAll( attributes.values .where((prop) => prop!.isIncludedInDefaultResultSet) @@ -118,14 +118,14 @@ class ManagedEntity implements APIComponentDocumenter { relationships.values .where( (prop) => - prop!.isIncludedInDefaultResultSet && + prop.isIncludedInDefaultResultSet && prop.relationshipType == ManagedRelationshipType.belongsTo, ) - .map((prop) => prop!.name), + .map((prop) => prop.name), ); _defaultProperties = List.unmodifiable(elements); } - return _defaultProperties; + return _defaultProperties!; } /// Name of primary key property. @@ -176,8 +176,8 @@ class ManagedEntity implements APIComponentDocumenter { return (runtime.instanceOfImplementation()..entity = this) as T; } - ManagedSet? setOf(Iterable objects) { - return runtime.setOfImplementation(objects) as ManagedSet?; + ManagedSet setOf(Iterable objects) { + return runtime.setOfImplementation(objects) as ManagedSet; } /// Returns an attribute in this entity for a property selector. diff --git a/packages/core/lib/src/db/managed/object.dart b/packages/core/lib/src/db/managed/object.dart index 83be20eb4..cb4a37f42 100644 --- a/packages/core/lib/src/db/managed/object.dart +++ b/packages/core/lib/src/db/managed/object.dart @@ -267,13 +267,13 @@ abstract class ManagedObject extends Serializable { /// var json = json.encode(model.asMap()); @override Map asMap() { - final outputMap = {}; + final outputMap = {}; backing.contents.forEach((k, v) { if (!_isPropertyPrivate(k)) { final property = properties[k]; final value = property!.convertToPrimitiveValue(v); - if (value == null && !_includeIfNull(property)) { + if (!_includeIfNull(property)) { return; } outputMap[mapKeyName(k)] = value; diff --git a/packages/core/lib/src/db/managed/validation/metadata.dart b/packages/core/lib/src/db/managed/validation/metadata.dart index 1730ef414..ec445d50a 100644 --- a/packages/core/lib/src/db/managed/validation/metadata.dart +++ b/packages/core/lib/src/db/managed/validation/metadata.dart @@ -479,7 +479,7 @@ class Validate { break; case ValidateType.oneOf: { - object.enumerated = _value as List?; + object.enumerated = _value as List?; } break; } diff --git a/packages/core/lib/src/db/query/mixin.dart b/packages/core/lib/src/db/query/mixin.dart index 49670723f..d6bf4e878 100644 --- a/packages/core/lib/src/db/query/mixin.dart +++ b/packages/core/lib/src/db/query/mixin.dart @@ -40,7 +40,7 @@ mixin QueryMixin List get propertiesToFetch => _propertiesToFetch ?? - entity.defaultProperties! + entity.defaultProperties .map((k) => KeyPath(entity.properties[k])) .toList(); @@ -167,7 +167,7 @@ mixin QueryMixin if (parent.subQueries.containsKey(fromRelationship.inverse)) { final validJoins = fromRelationship.entity.relationships.values .where((r) => !identical(r, fromRelationship)) - .map((r) => "'${r!.name}'") + .map((r) => "'${r.name}'") .join(", "); throw StateError( diff --git a/packages/core/lib/src/runtime/orm/data_model_compiler.dart b/packages/core/lib/src/runtime/orm/data_model_compiler.dart index 490fe53e0..8e1644fc5 100644 --- a/packages/core/lib/src/runtime/orm/data_model_compiler.dart +++ b/packages/core/lib/src/runtime/orm/data_model_compiler.dart @@ -160,8 +160,8 @@ class ManagedDataModelErrorImpl extends ManagedDataModelError { factory ManagedDataModelErrorImpl.duplicateInverse( String tableName, - String? inverseName, - List conflictingNames, + String inverseName, + List conflictingNames, ) { return ManagedDataModelErrorImpl( "Entity '$tableName' has multiple relationship " @@ -280,23 +280,11 @@ class ManagedDataModelErrorImpl extends ManagedDataModelError { "in this way."); } - static String? _getPersistentClassName(ManagedEntity entity) { - // if (entity == null) { - // return null; - // } - - // if (entity.tableDefinition == null) { - // return null; - // } - + static String _getPersistentClassName(ManagedEntity entity) { return entity.tableDefinition; } static String _getInstanceClassName(ManagedEntity entity) { - // if (entity.instanceType == null) { - // return null; - // } - return _getName(reflectType(entity.instanceType).simpleName); } diff --git a/packages/core/lib/src/runtime/orm/entity_builder.dart b/packages/core/lib/src/runtime/orm/entity_builder.dart index e67be69ed..9c4a440d0 100644 --- a/packages/core/lib/src/runtime/orm/entity_builder.dart +++ b/packages/core/lib/src/runtime/orm/entity_builder.dart @@ -52,7 +52,7 @@ class EntityBuilder { late final PropertyBuilder primaryKeyProperty; late final List properties; final Map attributes = {}; - final Map relationships = {}; + final Map relationships = {}; String get instanceTypeName => MirrorSystem.getName(instanceType.simpleName); @@ -149,7 +149,7 @@ class EntityBuilder { entity.symbolMap[Symbol("${p.propertyName}=")] = p.name; if (p.isRelationship) { - relationships[p.name] = p.relationship; + relationships[p.name] = p.relationship!; } else { attributes[p.name] = p.attribute; if (p.primaryKey) { @@ -162,7 +162,7 @@ class EntityBuilder { entity.relationships = relationships; entity.validators = []; entity.validators.addAll(attributes.values.expand((a) => a!.validators)); - entity.validators.addAll(relationships.values.expand((a) => a!.validators)); + entity.validators.addAll(relationships.values.expand((a) => a.validators)); entity.uniquePropertySet = uniquePropertySet ?.map((key) => entity.properties[key]) .whereType() diff --git a/packages/core/lib/src/runtime/orm/property_builder.dart b/packages/core/lib/src/runtime/orm/property_builder.dart index 1530d5375..8e2a7932f 100644 --- a/packages/core/lib/src/runtime/orm/property_builder.dart +++ b/packages/core/lib/src/runtime/orm/property_builder.dart @@ -28,12 +28,12 @@ class PropertyBuilder { .toList(); if (column?.validators.isNotEmpty ?? false) { - _validators! + _validators .addAll(column!.validators.map((v) => ValidatorBuilder(this, v))); } if (type?.isEnumerated ?? false) { - _validators!.add( + _validators.add( ValidatorBuilder( this, Validate.oneOf(type!.enumerationMap.values.toList()), @@ -48,7 +48,7 @@ class PropertyBuilder { final Column? column; final ResponseKey? responseKey; - List? get validators => _validators; + List get validators => _validators; Serialize? serialize; ManagedAttributeDescription? attribute; @@ -70,7 +70,7 @@ class PropertyBuilder { bool indexed = false; bool autoincrement = false; DeleteRule? deleteRule; - List? _validators; + late final List _validators; void compile(final List entityBuilders) { if (type == null) { @@ -97,7 +97,7 @@ class PropertyBuilder { name = column?.name ?? name; } - for (final vb in validators!) { + for (final vb in validators) { vb.compile(entityBuilders); } } @@ -144,13 +144,13 @@ class PropertyBuilder { ); } - for (final vb in validators!) { + for (final vb in validators) { vb.validate(entityBuilders); } } void link(List others) { - for (final v in validators!) { + for (final v in validators) { v.link(others); } if (isRelationship) { @@ -172,7 +172,7 @@ class PropertyBuilder { indexed: true, nullable: nullable, includedInDefaultResultSet: includeInDefaultResultSet, - validators: validators! + validators: validators .map((v) => v.managedValidator) .whereType() .toList(), @@ -194,7 +194,7 @@ class PropertyBuilder { nullable: nullable, includedInDefaultResultSet: includeInDefaultResultSet, autoincrement: autoincrement, - validators: validators! + validators: validators .map((v) => v.managedValidator) .whereType() .toList(), diff --git a/packages/core/lib/src/runtime/orm_impl.dart b/packages/core/lib/src/runtime/orm_impl.dart index 76a3af7f7..b8231e865 100644 --- a/packages/core/lib/src/runtime/orm_impl.dart +++ b/packages/core/lib/src/runtime/orm_impl.dart @@ -454,7 +454,7 @@ return entity.symbolMap[Symbol(symbolName)]; // Need to import any relationships types and metadata types // todo: limit import of importUris to only show symbols required to replicate metadata final directives = entity.relationships.values.map((r) { - var mirror = reflectType(r!.declaredType!); + var mirror = reflectType(r.declaredType!); if (mirror.isSubtypeOf(reflectType(ManagedSet))) { mirror = mirror.typeArguments.first; } diff --git a/packages/core/test/db/data_model_test.dart b/packages/core/test/db/data_model_test.dart index 3611539e6..72a71a10b 100644 --- a/packages/core/test/db/data_model_test.dart +++ b/packages/core/test/db/data_model_test.dart @@ -426,7 +426,7 @@ void main() { () { final dataModel = ManagedDataModel([TotalModel, PartialReferenceModel]); final defaultProperties = - dataModel.entityForType(TotalModel).defaultProperties!; + dataModel.entityForType(TotalModel).defaultProperties; expect(defaultProperties.contains("id"), true); expect(defaultProperties.contains("field"), true); expect(defaultProperties.contains("addedField"), true); @@ -434,7 +434,7 @@ void main() { expect( dataModel .entityForType(PartialReferenceModel) - .defaultProperties! + .defaultProperties .contains("foreignKeyColumn"), true, ); diff --git a/packages/postgresql/test/tiered_where_test.dart b/packages/postgresql/test/tiered_where_test.dart index c6a92a793..39f3bafd7 100644 --- a/packages/postgresql/test/tiered_where_test.dart +++ b/packages/postgresql/test/tiered_where_test.dart @@ -39,8 +39,8 @@ void main() { for (final r in results) { expect(r.backing.contents.containsKey("child"), false); - expect(r.backing.contents.length, r.entity.defaultProperties!.length); - for (final property in r.entity.defaultProperties!) { + expect(r.backing.contents.length, r.entity.defaultProperties.length); + for (final property in r.entity.defaultProperties) { expect(r.backing.contents.containsKey(property), true); } } @@ -53,9 +53,9 @@ void main() { for (final r in results) { expect( r.backing.contents.length, - r.entity.defaultProperties!.length + 1, + r.entity.defaultProperties.length + 1, ); // +1 is for key containing 'child' - for (final property in r.entity.defaultProperties!) { + for (final property in r.entity.defaultProperties) { expect(r.backing.contents.containsKey(property), true); } @@ -64,9 +64,9 @@ void main() { if (r.child != null) { expect( r.child!.backing.contents.length, - r.child!.entity.defaultProperties!.length, + r.child!.entity.defaultProperties.length, ); - for (final property in r.child!.entity.defaultProperties!) { + for (final property in r.child!.entity.defaultProperties) { expect(r.child!.backing.contents.containsKey(property), true); } } @@ -92,9 +92,9 @@ void main() { for (final r in results) { expect( r.backing.contents.length, - r.entity.defaultProperties!.length + 1, + r.entity.defaultProperties.length + 1, ); // +1 is for key containing 'child' - for (final property in r.entity.defaultProperties!) { + for (final property in r.entity.defaultProperties) { expect(r.backing.contents.containsKey(property), true); } @@ -103,9 +103,9 @@ void main() { if (r.child != null) { expect( r.child!.backing.contents.length, - r.child!.entity.defaultProperties!.length, + r.child!.entity.defaultProperties.length, ); - for (final property in r.child!.entity.defaultProperties!) { + for (final property in r.child!.entity.defaultProperties) { expect(r.child!.backing.contents.containsKey(property), true); } expect(r.child!.backing.contents.containsKey("grandChild"), false); @@ -122,9 +122,9 @@ void main() { for (final r in results) { expect( r.backing.contents.length, - r.entity.defaultProperties!.length + 1, + r.entity.defaultProperties.length + 1, ); // +1 is for key containing 'child' - for (final property in r.entity.defaultProperties!) { + for (final property in r.entity.defaultProperties) { expect(r.backing.contents.containsKey(property), true); } @@ -132,9 +132,9 @@ void main() { if (r.child != null) { expect( r.child!.backing.contents.length, - r.child!.entity.defaultProperties!.length + 1, + r.child!.entity.defaultProperties.length + 1, ); // +1 is for key containing 'grandchild - for (final property in r.child!.entity.defaultProperties!) { + for (final property in r.child!.entity.defaultProperties) { expect(r.child!.backing.contents.containsKey(property), true); } @@ -142,10 +142,10 @@ void main() { if (r.child!.grandChild != null) { expect( r.child!.grandChild!.backing.contents.length, - r.child!.grandChild!.entity.defaultProperties!.length, + r.child!.grandChild!.entity.defaultProperties.length, ); for (final property - in r.child!.grandChild!.entity.defaultProperties!) { + in r.child!.grandChild!.entity.defaultProperties) { expect( r.child!.grandChild!.backing.contents.containsKey(property), true, @@ -508,9 +508,9 @@ void main() { for (final r in results) { expect( r.backing.contents.length, - r.entity.defaultProperties!.length + 1, + r.entity.defaultProperties.length + 1, ); // +1 is for child - for (final property in r.entity.defaultProperties!) { + for (final property in r.entity.defaultProperties) { expect(r.backing.contents.containsKey(property), true); } expect(r.child!.backing.contents.length, 1);