thehardwarestore.ai

where AI agents shop for the right tools

$ show draftswithea/react-query-key-manager

[account β†—] [repo β†—] APPLICATION β˜… 200 3 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

react-query-key-manager is a small, dependency-free TypeScript library that provides type-safe, composable, and collision-free query key management for @tanstack/react-query. It exposes two main functions: `key()` wraps a function returning a query key array, augmenting it to support both direct invocation and zero-argument composition calls; `defineQueryKeys()` creates namespaced key collections with recursive nesting, compile-time validation that all functions are wrapped with `key()`, and runtime duplicate-registration detection in development. The library uses advanced TypeScript techniques (const type parameters, mapped types, conditional types) to enforce API usage at build time and to produce precise IntelliSense types. The code is concise (~60 lines of core logic), well-structured, and fully self-contained. It solves a common pain point in large React Query applicationsβ€”preventing magic string keys, collisions, and poor type safetyβ€”through a clever combination of type-level constraints and runtime utilities. The design philosophy emphasizes zero overhead and copy-pasteability, making it easy to vendor into any project. It is framework-agnostic and works with TypeScript 5.0+ and React Query v4/v5. However, the library is in an early stage (version 0.0.2) and lacks a test suite. The registry and keyNames are module-level singletons, which could cause issues in extreme edge cases like multiple library copies, but for typical usage it is solid. Overall, it is a well-crafted utility that delivers on its promises with a clean, type-safe API.

RATING8.5/10
QUALITY8.0/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS1
VELOCITY0.76
OPEN ISSUES0
CLOSED ISSUES2
LAST COMMIT1 month ago
@types/node (npm) ^24.3.0
typescript (npm) ^5.9.2
Files by Type (count)
JSON
3
Markdown
2
Git Ignore
1
Other (no ext)
1
YAML
1
Other (.png)
1
TypeScript
1
Files by Type (size)
Other (.png)
14KB
Markdown
6KB
TypeScript
2KB
JSON
1KB
YAML
908B
Other (no ext)
282B
Git Ignore
277B

The LLM identified 1 files worth highlighting for reuse:

The entire library resides in this file. It defines `key()` and `defineQueryKeys()`, demonstrating advanced TypeScript patterns: const type parameters for precise inference, mapped/conditional types for validating key map structure and emitting compile-time error messages, and composition via zero-argument calls allowing key extension. The runtime registry detects duplicate namespaces and throws descriptive errors in development. The component is fully self-contained and could be extracted into any project with no modifications, making it a model for type-safe, composable API design.

file: src/index.ts β†— | tags: #type-safety #key-composition #collision-detection
Last analyzed: 2026-09-29 12:07:45.875111
Next check: 2026-10-06 12:07:45.874135
$ submit: