refactor: expose Query::shape() as iterative instance method#4
Conversation
Per review: make the canonical-shape helper a public instance method on Query (`shape()`) rather than a private static inside `fingerprint()`, and replace the recursive walk with an iterative stack-based post-order traversal. Added test covering leaf, logical, elemMatch, and 4-level-deep nested shapes to verify iterative equivalence with the previous recursive version.
Greptile SummaryThis PR extracts a canonical shape computation from Confidence Score: 5/5Safe to merge — no correctness, security, or data-integrity issues found. All findings are P2 or lower. The core invariant (children resolved before parents in the reversed list) holds by construction of a preorder traversal, and tests cover leaf, logical, elemMatch, and 4-level-deep nesting. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "refactor: expose shape() as an iterative..." | Re-trigger Greptile |
Follow-up to #3 — per @abnegate's review comment:
Changes
fingerprint()and into a public instance methodQuery::shape().fingerprint()now just calls$query->shape()on each element.API
Test plan
Added
testShape()covering leaf, logical,elemMatch, and 4-level-deep nested queries. Confirms iterative output matches the recursive baseline and thatelemMatch's attribute is preserved in its shape.Mirrors the same refactor applied to utopia-php/database#859.