feat(db): type nested include in IncludeOption (#2286)#2314
Merged
Conversation
Add TModels generic parameter to IncludeOption, IncludeResolve, ResolveOneInclude, FindResult, FindOptions, ModelDelegate, TypedGetOptions, TypedListOptions, DatabaseClient, and TransactionClient. When TModels is provided, nested include keys are validated against the target model's relations and the output type reflects nested relation data. New type utilities: FindModelByTable (bidirectional structural match), FindModelRelations, NestedInclude. Depth cap at 3 typed nesting levels (matching existing IncludeResolve cap). Default TModels falls back to untyped Record<string, unknown> for backward compatibility. Type tests cover: manual models, createRegistry models, self-referencing relations, M2M through-relations, depth cap fallback, false/undefined exclusion, nested select narrowing, and full DatabaseClient/TransactionClient end-to-end chain. Follow-up: #2309 (entity-layer TypedIncludeOption) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix never-distribution bug in FindModelRelations (tuple-wrap check) - Add negative tests for self-referencing and M2M through-relations - Add negative test for list() nested include through DatabaseClient - Add standalone tests for FindModelByTable and FindModelRelations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DatabaseClient<TModels> now maps delegates as ModelDelegate<TEntry, TModels>. The Extends assertion needs the full TModels type parameter to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 5, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TModelsgeneric parameter toIncludeOption,IncludeResolve,ResolveOneInclude,FindResult,FindOptions,ModelDelegate,TypedGetOptions,TypedListOptions,DatabaseClient, andTransactionClientTModelsis provided, nestedincludekeys are validated against the target model's relations and output types reflect nested relation dataFindModelByTable(bidirectional structural match),FindModelRelations,NestedIncludeIncludeResolveruntime cap)TModelsfalls back to untypedRecord<string, unknown>for full backward compatibilityPublic API Changes
IncludeOptionTModelsand_Depthparams (defaulted)IncludeResolveTModelsparam (defaulted)FindResultTModelsparam (defaulted)FindOptionsTModelsparam (defaulted)ModelDelegateTModelsparam (defaulted)FindModelByTableFindModelRelationsAll changes are backward compatible — existing code using these types without
TModelscontinues to compile unchanged.Test Coverage
FindResult, nestedselectnarrowingfalse/undefinedexclusionModelEntryconstruction andcreateRegistry-produced modelsDatabaseClient.get(),DatabaseClient.list(),TransactionClient(positive + negative)FindModelByTable,FindModelRelationswith backward compat verificationPhase Review
FindModelRelationsnever-distribution bug)Follow-up
TModelsthrough entity-layerTypedIncludeOptionCloses #2286
🤖 Generated with Claude Code