mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
/**
|
|
* Reusable query key factory utilities
|
|
* Reduces duplication across API hooks and ensures consistent key structure
|
|
*/
|
|
|
|
/**
|
|
* Creates a standard query key factory for a resource
|
|
* Follows React Query best practices for hierarchical keys
|
|
*/
|
|
export function createQueryKeyFactory<T extends string>(resourceName: T) {
|
|
return {
|
|
all: [resourceName] as const,
|
|
lists: () => [...[resourceName], 'list'] as const,
|
|
list: (filters?: Record<string, unknown>) => [...[resourceName], 'list', filters] as const,
|
|
details: () => [...[resourceName], 'detail'] as const,
|
|
detail: (id: string) => [...[resourceName], 'detail', id] as const,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Extended query key factory with additional scopes
|
|
* Useful for resources with relationships (e.g., byOrganization, bySite)
|
|
*/
|
|
export function createExtendedQueryKeyFactory<T extends string>(
|
|
resourceName: T,
|
|
additionalScopes?: Record<string, (param: unknown) => readonly unknown[]>
|
|
) {
|
|
const base = createQueryKeyFactory(resourceName);
|
|
|
|
const extended = {
|
|
...base,
|
|
};
|
|
|
|
if (additionalScopes) {
|
|
for (const [scopeName, scopeFn] of Object.entries(additionalScopes)) {
|
|
(extended as Record<string, unknown>)[scopeName] = scopeFn;
|
|
}
|
|
}
|
|
|
|
return extended;
|
|
}
|