1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* IMPORT */
import * as z from 'zod';
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from 'nuqs/server';
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { type RegEvalCriteriaView } from "@/db/schema";
// ----------------------------------------------------------------------------------------------------
/* QUERY PARAMETER SCHEMATA */
const searchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(['advancedTable', 'floatingBar'])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
sort: getSortingStateParser<RegEvalCriteriaView>().withDefault([
{ id: 'criteriaId', desc: false },
{ id: 'orderIndex', desc: false },
]),
tagTypeLabel: parseAsString.withDefault(''),
classLabel: parseAsString.withDefault(''),
formCode: parseAsString.withDefault(''),
formName: parseAsString.withDefault(''),
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(['and', 'or']).withDefault('and'),
search: parseAsString.withDefault(''),
});
// ----------------------------------------------------------------------------------------------------
/* TYPES */
type GetRegEvalCriteriaSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>;
// ----------------------------------------------------------------------------------------------------
/* EXPORT */
export {
searchParamsCache,
type GetRegEvalCriteriaSchema,
};
|