Skip to content

Conversation

@muzix
Copy link
Owner

@muzix muzix commented Aug 31, 2025

Add KeyTuple Support and Clean Up Query Key Types

This PR enhances the SwiftUI Query library's type system by adding comprehensive support for
KeyTuple types and removing deprecated query key implementations.

✨ New Features

KeyTuple Support for UseQuery

  • Added convenience initializers for UseQuery supporting KeyTuple2, KeyTuple3, and
    KeyTuple4
  • All initializers maintain full parameter compatibility with existing API
  • Type-safe query functions that receive the exact KeyTuple type

KeyTuple Support for UseInfiniteQuery

  • Added convenience initializers for UseInfiniteQuery supporting all KeyTuple types
  • Consistent API design matching UseQuery initializers
  • Full infinite query functionality with strongly-typed keys

Dictionary Query Key Support

  • Added UseQuery initializer for Dictionary<K,V> query keys
  • Dictionary keys use JSON encoding with sorted keys for consistent hashing
  • Comprehensive tests for dictionary query key behavior

🔧 Improvements

Query Key Protocol Enhancement

  • Made QueryKey protocol conform to Equatable for better type checking
  • Improved query hash consistency with sorted JSON encoding
  • Enhanced type safety across the query system

🧹 Cleanup

Removed Deprecated Types

  • Removed ArrayQueryKey struct (use native Array extension instead)
  • Removed GenericQueryKey struct (use native type conformances instead)
  • Updated all related tests to use native Swift types

📊 Test Coverage

Comprehensive Test Suite

  • Added KeyTupleTests with 9 new test cases covering all KeyTuple types
  • Dictionary query key tests for hashing consistency and uniqueness
  • InfiniteQuery options tests for KeyTuple integration
  • Updated existing tests to use native Array types
  • All 182 tests pass with full Swift 6 strict concurrency compliance

🚀 Benefits

  • Better Type Safety: KeyTuple types provide compile-time guarantees for query keys
  • Improved Developer Experience: Cleaner API with fewer wrapper types
  • Performance: Native Swift types perform better than custom wrappers
  • Consistency: Unified approach to query key handling across the library

🔄 Breaking Changes

  • Removed ArrayQueryKey and GenericQueryKey types
  • Code using these types should migrate to native Swift arrays and types
  • All functionality is preserved through native type extensions

Test Plan

  • All existing tests pass (182/182)
  • New KeyTuple initializers compile and work correctly
  • Dictionary query keys generate consistent hashes
  • Swift 6 strict concurrency compliance maintained
  • No performance regressions in query operations

This PR maintains full backward compatibility for users already using String, Array, and custom
types as query keys while adding powerful new KeyTuple support for complex query scenarios.

@muzix muzix merged commit b768948 into main Aug 31, 2025
0 of 2 checks passed
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.

2 participants