fix: Propagate subject type - #588
Conversation
There was a problem hiding this comment.
The PR introduces TypedRef<T> as a branded wrapper around cqn_ref to propagate the entity type through bound action handlers into CQL query builders (SELECT, DELETE, UPDATE). The core idea is sound, but the brand field being optional (__entity?: T) means it is not a true discriminant — any plain cqn_ref satisfies TypedRef<T>, and the four new overloads are all ordered before their cqn_ref fallbacks, causing plain refs to silently match the typed overload and infer T = unknown instead of falling through to _TODO.
PR Bot Information
Version: 1.29.33
- LLM:
anthropic--claude-4.6-sonnet - Event Trigger:
pull_request.opened - Correlation ID:
2ecc3300-9bbb-11f1-98c4-113ca607fd21 - File Content Strategy: Full file content
SummaryThe following content is AI-generated and provides a summary of the pull request: Fix: Propagate Subject Type Through Bound Action HandlersBug Fix🐛 Fixes the propagation of the entity subject type in bound action handlers. Previously, Changes
GitHub Issues
PR Bot InformationVersion:
|
There was a problem hiding this comment.
The PR introduces utility types to propagate the subject type through bound action handlers and adds typed overloads for CQL operations. The implementation has several overload-ordering issues (already flagged) and a dead-code branch in EntityClassFromInstance where the else arm is unreachable because every TypeScript object structurally satisfies { constructor: infer C }. Additionally, the new NonConstructable<T> overload for UPDATE.entity is positioned before the cqn_ref explicit fallback, meaning a bare cqn_ref value could match the new overload and return a wrongly-typed UPDATE<cqn_ref> instead of UPDATE<StaticAny>. Please address the open comments before merging.
PR Bot Information
Version: 1.29.33
- Event Trigger:
pull_request.ready_for_review - File Content Strategy: Full file content
- Correlation ID:
eb4a1d90-9c91-11f1-9859-adb332e327e6 - LLM:
anthropic--claude-4.6-sonnet
Fixes #590
Fix: Propagate Subject Type Through Bound Action Handlers
Bug Fix
🐛 Fixes the propagation of the entity subject type in bound action handlers. Previously,
req.subjectin bound action handlers was untyped, preventing type-safe usage with CQL operations likeSELECT,UPDATE, andDELETE. This change carries the entity type information through thesubjectproperty, enabling full type inference when usingreq.subjectin database queries.Changes
apis/ql.d.ts: IntroducedClassInstanceandEntityClassFromInstance<T>utility types to derive an entity class type from an instance. Added typed overloads forSELECT.one.from,SELECT.from,DELETE.from, andUPDATE.entitythat accept a class instance (subject) and return properly typed results.apis/services.d.ts: UpdatedActionRequest<P, S>to explicitly omit and re-declare thesubjectproperty so it is properly typed asS(the bound action's instance type) rather than being inherited asany.test/typescript/apis/project/cds-services.ts: Updated the bound action handler test toasyncand added assertions verifying thatSELECT.one.from,SELECT.from,DELETE.from, andUPDATEcorrectly infer the entity type when called withreq.subject.test/typescript/apis/project/dummy.ts: Addeddeclare static readonly kind: 'entity'to theFooclass to satisfy theEntityClassFromInstanceconstraint, and minor formatting fix.CHANGELOG.md: Documented the new behavior — bound action handlers now keepreq.subjecttyped as the bound action's instance type, and subject-based query overloads now derive the entity class from the passed subject to preserve typed query results.PR Bot Information
Version:
1.29.33anthropic--claude-4.6-sonnetpull_request.edited5e4a13a0-9c91-11f1-8ebb-e301069f6ab9