Skip to content

Entity model clean-up and fixes (v1.35.0) - #208

Closed
gmpassos wants to merge 6 commits into
masterfrom
refactor/entity-model-cleanup
Closed

gmpassos wants to merge 6 commits into
masterfrom
refactor/entity-model-cleanup

Conversation

@gmpassos

@gmpassos gmpassos commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Clean-up of the entity model (bones_api_entity.dart, _entity_rules, _entity_reference, _entity_pagination, _extension, _types, _utils_collections): behavior-preserving refactors, plus a few bug fixes (separate commit, each tested).

Refactors (behavior-preserving)

  • Entity rules: EntityResolutionRules.merge → _mergeFlag / _mergeTypesDroppingConflict; fetchTypes → _typesWhere; EntityAccessRules → _flattenGroup, _conditionMatches, _lastDefined (static: the class is implemented by others).
  • Equality/comparison: _equalsValuesScalar (shared by equalsValues/equalsValuesBasic; equalsEntityReferenceBase and == kept in place), _isCollectionLike, _entityHandlerForValue, _compareAsNumbers.
  • Provider lookups: documented _asReiterable(); Iterable getEntityRepositoryByTypeInfo calls the Impl; _whereNotClosed without the redundant parameter; _openRepositoryOrNull; allRepositories uses traversed.add. List/Set extensions kept as forwarders.
  • Transaction: identity-set caches beside _operations/_executedOperations (kept in sync in add/mark/dispose) for O(1) membership; the Lists still give order, op.id and the unmodifiable views.
  • Cascade delete: _addSubEntitiesDeleteCalls; _resolveRepositoryProvider → _resolveEntityRepository.
  • storeAllFromJson: _createAndStoreAll, named/documented block-size constants, _logCreateFromMapError, _isFieldChanged; seed JSON _toEntitiesJson; resolveEntitySourceValueVariables flattened.
  • Handlers: _getCachedFieldType (shared by Generic/ClassReflection getFieldType), _inspectedOrThrow (same messages); list resolution hoisted; _resolveEntityHandler without the always-true guards.
  • TransactionOperation: _describe() for the toString heads; TransactionOperationTypeExtension.name → (this as Enum).name.
  • IterableEntityRepository: _relationshipFieldType, _matchesEntity; hasReferencedEntities tail explained; _createFromMapDefaultImpl uses _getIDFunction.
  • References: _fromInstantiator, EntityInstantiatorHandler.resolveEntityMap reused, _toStringPrefix, _compareIDPresence (list-vs-list arm now tested), dead branch in _castListNullable removed.
  • Extensions: merged parseEntity/entityType branches, _castEntityHandler, _parseValue, one key loop, _scanKeyIgnoreCase (shared by getIgnoreCase/matchKeyIgnoreCase, keeping each one's exact-key check); docs fixed (defaultValue, getMultiKeyAsString parses as String).
  • Time: _toOffsetDuration, _hasHmsPrefix. Pagination: _completePageLoad, duplicate final-page check dropped. Collections: iterators instead of elementAt(i).
  • Cache fields: renamed *Cache, documented (what/why), declared before the methods that fill them (EntityHandler, Generic/ClassReflection handlers, EntityAccessRulesCached).

Deprecations (still working)

  • EntityHandler.graterThanValue / graterThanOrEqualValue → greaterThanValue / greaterThanOrEqualValue (bones_api_condition.dart still calls the old names; untouched here).
  • EntityRulesResolver.cotextProviders → contextProviders.

Bug fixes (test/bones_api_entity_model_fixes_test.dart; all 8 fail on the pre-fix code)

  • GenericEntityHandler.getFieldType: asks the entity for the resolved field name.
  • populateFromSource: forwards workingPath.
  • EntityRepositoryProviderExtension.storeAllFromJson: uses transaction (forwarded to each repository; executeBlock runs inside a given transaction without committing it) and resolves variables (populateFromSource now delegates that, so it's resolved once).
  • EntityReference.from / EntityReferenceList.from: forward entityHandlerProvider.
  • IterableEntityRepository.deleteEntity: forwards transaction.
  • EntityAccessRules ==/hashCode: entityFields element-wise.
  • EntityResolutionRules with allEager and allLazy both true: invalid (validate/merge throw ValidateEntityRulesError), and the isEagerEntityType/isLazyEntityType mutual recursion is broken (same results whenever only one is set).

Version

v1.34.0 is tagged: bumped to 1.35.0 (pubspec.yaml, BonesAPI.VERSION), ## 1.35.0 CHANGELOG section.

Local tests

dart format and dart analyze --fatal-infos lib test: clean. Ran (no Docker, no benchmarks): entity_rules, cov_entity_rules, cov_entity_handler, entity_provider_lookup, cov_entity_repository, cov_db_adapter_base, cov_transaction, entity_instantiate, cov_db_repository_relational, cov_entity_reference, entity, cov_extension, types, cov_types, entity_pagination, utils_collection, entity_mapping, entity_reflection, cov_security, entity_model_fixes, version (474 passed); entity_db_memory + entity_db_sqlite (480 passed); cov_condition + condition_not (84 passed). Full suites left to CI.

🤖 Generated with Claude Code

gmpassos and others added 6 commits November 8, 2026 05:16
- EntityResolutionRules.merge: the tri-state flag merge -> _mergeFlag; the
  tolerant/intolerant mirror arms -> _mergeTypesDroppingConflict.
- fetchTypes: four near-identical lambdas -> _typesWhere.
- EntityAccessRules: _flattenGroup, _conditionMatches, _lastDefined; the
  block arm returns fieldRule directly.
- EntityAccessRulesCached: cache fields named *Cache and documented.
- EntityRulesResolver.contextProviders (cotextProviders kept, deprecated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Equality: _equalsValuesScalar (the DateTime/Time/DynamicNumber/primitive/
  enum chain of equalsValues and equalsValuesBasic), _isCollectionLike,
  _entityHandlerForValue; comparisons via _compareAsNumbers.
- greaterThanValue/greaterThanOrEqualValue; the misspelled
  graterThan* kept as @deprecated forwarders.
- Provider lookups: _asReiterable (documented), Iterable
  getEntityRepositoryByTypeInfo calls the Impl; _whereNotClosed without
  the redundant parameter; _openRepositoryOrNull; allRepositories uses
  traversed.add.
- Transaction: identity-set caches beside _operations/_executedOperations
  for O(1) membership (bulk storeAll was O(n^2)).
- Cascade delete: _addSubEntitiesDeleteCalls; _resolveRepositoryProvider
  renamed _resolveEntityRepository.
- storeAllFromJson: _createAndStoreAll, named block-size constants;
  _logCreateFromMapError; _isFieldChanged; seed JSON _toEntitiesJson;
  resolveEntitySourceValueVariables flattened.
- Handlers: _getCachedFieldType (shared by Generic/ClassReflection
  getFieldType), _inspectedOrThrow; list resolution hoisted;
  _resolveEntityHandler without always-true guards.
- TransactionOperation: _describe() for the toString heads;
  TransactionOperationType.name is (this as Enum).name.
- IterableEntityRepository: _relationshipFieldType, _matchesEntity,
  hasReferencedEntities explained.
- Private cache fields named *Cache and documented (EntityHandler,
  GenericEntityHandler, ClassReflectionEntityHandler).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- EntityReference.fromJson: _fromInstantiator for the two instantiator
  blocks; uses EntityInstantiatorHandler.resolveEntityMap (the private
  duplicate removed).
- EntityReferenceBase: _toStringPrefix and _compareIDPresence shared by
  EntityReference and EntityReferenceList (the list-vs-list arm now
  tested); dead branch in _castListNullable removed.
- TypeInfo extension: parseEntity/entityType merged branches;
  _castEntityHandler for the castCall of toEntityReference(List).
- MapGetterExtension: _parseValue (getParsed/getMultiKeyParsed tail), one
  key loop, _scanKeyIgnoreCase shared by getIgnoreCase and
  matchKeyIgnoreCase; docs name defaultValue (not def), and
  getMultiKeyAsString parses as String.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Time: +/- share _toOffsetDuration; _bytesInStringFormat uses
  _hasHmsPrefix.
- EntityPagination: loadPage's sync/async success path -> _completePageLoad;
  _loadAllImpl's redundant final-page check removed (_isPageKnownEmpty).
- isEqualsIterableDeep: paired iterators; intersectsIterableDeep
  iterates (materializing a lazy it2 once) instead of elementAt(i)
  (O(n^2) on a non-List Iterable).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GenericEntityHandler.getFieldType: the entity instance is asked for the
  resolved field name (it was asked for the original key again).
- EntityRepositoryProviderExtension.populateFromSource: forwards
  workingPath to resolveEntitiesSource (and resolveSource for variables).
- EntityRepositoryProviderExtension.storeAllFromJson: uses transaction
  (forwarded to each repository) and resolves the variables placeholders
  (populateFromSource now lets it do so, once).
- EntityReference.from / EntityReferenceList.from: forward
  entityHandlerProvider.
- IterableEntityRepository.deleteEntity: forwards transaction.
- EntityAccessRules ==/hashCode: entityFields compared/hashed
  element-wise (was identity).
- EntityResolutionRules: allEager and allLazy both true is invalid
  (validate/merge throw ValidateEntityRulesError), and
  isEagerEntityType/isLazyEntityType no longer recurse forever on it.

Tests: test/bones_api_entity_model_fixes_test.dart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmpassos added a commit that referenced this pull request Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	CHANGELOG.md
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.53596% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.81%. Comparing base (32e1dbf) to head (d2d99dc).

Files with missing lines Patch % Lines
lib/src/bones_api_entity.dart 99.63% 1 Missing ⚠️
lib/src/bones_api_extension.dart 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
- Coverage   95.85%   95.81%   -0.04%     
==========================================
  Files          75       75              
  Lines       26519    26434      -85     
==========================================
- Hits        25419    25329      -90     
- Misses       1100     1105       +5     
Flag Coverage Δ
unittests 95.81% <99.53%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmpassos

gmpassos commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged into the single v1.35.0 PR: #209.

@gmpassos gmpassos closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant