gitscope
← marzneshin / v0.5.3 / dashboard/src/features/entity-table/hooks/use-entity-query.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/entity-table/hooks/use-entity-query.ts · TypeScript
Blame Raw
 1import { z } from "zod";
 2
 3const UseEntityQueryPropsSchema = z.object({
 4    page: z.number().gte(1),
 5    size: z.number().gte(1).lte(100),
 6    search: z.string().optional()
 7})
 8
 9export interface SortableEntitySortQueryProps {
10    sortBy: string
11    desc: boolean
12}
13
14export type UseEntityQueryProps = z.infer<typeof UseEntityQueryPropsSchema & SortableEntitySortQueryProps>
15
16export type QueryKey =
17    [string, number, number, string]
18export type SortableQueryKey =
19    [string, number, number, string, string, boolean]
20export type SidebarQueryKey =
21    [string, number | string | undefined, string, number, number, string]
22export type SortableSidebarQueryKey =
23    [string, number | string | undefined, string, number, number, string, string, boolean]
24
25export interface QueryKeyType<QT> {
26    queryKey: QT
27}
28
29export type EntityQueryKeyType = QueryKeyType<SortableQueryKey | QueryKey>
30export type EntitySidebarQueryKeyType = QueryKeyType<SortableSidebarQueryKey | SidebarQueryKey>
31
32interface FetchEntityResult<T> {
33    pageCount: number
34    entity: T[]
35}
36
37export type FetchEntityReturn<T> = Promise<FetchEntityResult<T>>