Fix single-value property traversals returning arrays#45
Merged
Conversation
fix: mutation input safety and custom ID support in SparqlStore
chore: version package for release
chore: version package for release
…le values Properties with maxCount <= 1 (e.g. bestFriend) were always wrapped in ResultRow[] arrays after SPARQL result mapping. Now maxCount is propagated through the IR pipeline (DesugaredPropertyStep → IRTraversePattern → NestedGroup) and used in result mapping to unwrap single-value traversals to a single ResultRow or null. https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1
Adds a selectBestFriendOnly fixture and an inline snapshot golden test that asserts the bestFriend traverse pattern carries maxCount: 1 from PropertyShape through desugar/lower to the final IRSelectQuery. https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1
- Changeset: patch bump for @_linked/core documenting the behavioral change - Report: docs/reports/012-fix-single-value-property-result.md with full architecture, file inventory, test coverage, and known gap https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1
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
Properties decorated with
@objectProperty({maxCount: 1})(e.g.,bestFriend) now correctly return a singleResultRow(ornullwhen absent) instead ofResultRow[]when accessed via traversal queries likePerson.select(p => p.bestFriend.name).Root Cause
The
maxCountmetadata fromPropertyShapewas never propagated through the IR pipeline.IRTraversePatternhad nomaxCountfield, so the result mapping layer had no way to distinguish single-value from multi-value traversals, causing all nested groups to be returned as arrays.Key Changes
IntermediateRepresentation.ts: Added optionalmaxCount?: numberfield toIRTraversePatternIRDesugar.ts: PropagatedmaxCountfromPropertyShapethroughDesugaredPropertyStepinsegmentsToSteps()anddesugarEntry()IRLower.ts: ExtendedgetOrCreateTraversal()andPathLoweringOptions.resolveTraversalsignatures to accept and applymaxCountto traverse patternsIRProjection.ts: UpdatedProjectionPathLoweringOptions.resolveTraversalsignature to forwardmaxCountfrom desugared stepsresultMapping.ts:maxCount?: numbertoNestedGrouptypemaxCountthroughbuildAliasChain(),insertIntoTree(), andbuildNestingDescriptor()assignNestedGroupValue()helper that unwraps single-value properties (wheremaxCount <= 1) from arrays to a singleResultRowornullmaxCountpropagation through the full pipelineImplementation Details
maxCountis propagated as an optional field through each layer of the IR pipeline, maintaining backward compatibilitynull(consistent withsingleResultbehavior), notundefinedor empty arraysmaxCountconstraints continue to return arrays as beforeBreaking Change
Code accessing single-value traversal results as arrays (e.g.,
result.bestFriend[0]) must be updated to access the value directly (e.g.,result.bestFriend).https://claude.ai/code/session_017mqanCkMvA1VU8MVD7hkA1