adorn-api 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,7 @@ import type { Filter, FilterFieldInput, FilterMapping, FilterOperator, ParseFilt
|
|
|
5
5
|
* @param mappings - Filter field mappings
|
|
6
6
|
* @returns Parsed filter or undefined
|
|
7
7
|
*/
|
|
8
|
-
export declare function parseFilter<T, K extends keyof T>(query:
|
|
8
|
+
export declare function parseFilter<T, K extends keyof T>(query: object | undefined, mappings: Record<string, FilterMapping<T>>): Filter<T, K> | undefined;
|
|
9
9
|
export declare function parseFilter<T, K extends keyof T>(options: ParseFilterOptions<T>): Filter<T, K> | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Creates filter mappings for an entity.
|
|
@@ -5,4 +5,4 @@ import type { PaginationConfig, ParsedPagination } from "./types";
|
|
|
5
5
|
* @param config - Pagination configuration
|
|
6
6
|
* @returns Parsed pagination result
|
|
7
7
|
*/
|
|
8
|
-
export declare function parsePagination(query:
|
|
8
|
+
export declare function parsePagination(query: object, config?: PaginationConfig): ParsedPagination;
|
|
@@ -10,11 +10,12 @@ const coerce_1 = require("../../core/coerce");
|
|
|
10
10
|
*/
|
|
11
11
|
function parsePagination(query, config = {}) {
|
|
12
12
|
const { defaultPageSize = 25, maxPageSize = 100 } = config;
|
|
13
|
-
const
|
|
13
|
+
const q = query;
|
|
14
|
+
const page = coerce_1.coerce.integer(q.page, {
|
|
14
15
|
min: 1,
|
|
15
16
|
clamp: true
|
|
16
17
|
}) ?? 1;
|
|
17
|
-
const pageSize = coerce_1.coerce.integer(
|
|
18
|
+
const pageSize = coerce_1.coerce.integer(q.pageSize, {
|
|
18
19
|
min: 1,
|
|
19
20
|
max: maxPageSize,
|
|
20
21
|
clamp: true
|
package/package.json
CHANGED
|
@@ -7,14 +7,14 @@ import type { Filter, FilterFieldInput, FilterMapping, FilterOperator, ParseFilt
|
|
|
7
7
|
* @returns Parsed filter or undefined
|
|
8
8
|
*/
|
|
9
9
|
export function parseFilter<T, K extends keyof T>(
|
|
10
|
-
query:
|
|
10
|
+
query: object | undefined,
|
|
11
11
|
mappings: Record<string, FilterMapping<T>>
|
|
12
12
|
): Filter<T, K> | undefined;
|
|
13
13
|
export function parseFilter<T, K extends keyof T>(
|
|
14
14
|
options: ParseFilterOptions<T>
|
|
15
15
|
): Filter<T, K> | undefined;
|
|
16
16
|
export function parseFilter<T, K extends keyof T>(
|
|
17
|
-
queryOrOptions:
|
|
17
|
+
queryOrOptions: object | ParseFilterOptions<T> | undefined,
|
|
18
18
|
mappings?: Record<string, FilterMapping<T>>
|
|
19
19
|
): Filter<T, K> | undefined {
|
|
20
20
|
const options = mappings ? undefined : (queryOrOptions as ParseFilterOptions<T> | undefined);
|
|
@@ -49,13 +49,13 @@ export function parseFilter<T, K extends keyof T>(
|
|
|
49
49
|
|
|
50
50
|
return hasValues ? (filter as Filter<T, K>) : undefined;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates filter mappings for an entity.
|
|
55
|
-
* @param entity - Entity type
|
|
56
|
-
* @param fields - Array of field definitions
|
|
57
|
-
* @returns Filter mappings
|
|
58
|
-
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates filter mappings for an entity.
|
|
55
|
+
* @param entity - Entity type
|
|
56
|
+
* @param fields - Array of field definitions
|
|
57
|
+
* @returns Filter mappings
|
|
58
|
+
*/
|
|
59
59
|
export function createFilterMappings<T extends Record<string, unknown>>(
|
|
60
60
|
_entity: T,
|
|
61
61
|
fields: Array<{ queryKey: string; field: FilterFieldInput<T>; operator?: FilterOperator }>
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import type { PaginationConfig, ParsedPagination } from "./types";
|
|
2
|
-
import { coerce } from "../../core/coerce";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Parses pagination parameters from query parameters.
|
|
6
|
-
* @param query - Query parameters
|
|
7
|
-
* @param config - Pagination configuration
|
|
8
|
-
* @returns Parsed pagination result
|
|
9
|
-
*/
|
|
10
|
-
export function parsePagination(
|
|
11
|
-
query:
|
|
12
|
-
config: PaginationConfig = {}
|
|
13
|
-
): ParsedPagination {
|
|
14
|
-
const { defaultPageSize = 25, maxPageSize = 100 } = config;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import type { PaginationConfig, ParsedPagination } from "./types";
|
|
2
|
+
import { coerce } from "../../core/coerce";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses pagination parameters from query parameters.
|
|
6
|
+
* @param query - Query parameters
|
|
7
|
+
* @param config - Pagination configuration
|
|
8
|
+
* @returns Parsed pagination result
|
|
9
|
+
*/
|
|
10
|
+
export function parsePagination(
|
|
11
|
+
query: object,
|
|
12
|
+
config: PaginationConfig = {}
|
|
13
|
+
): ParsedPagination {
|
|
14
|
+
const { defaultPageSize = 25, maxPageSize = 100 } = config;
|
|
15
|
+
const q = query as Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
const page = coerce.integer(q.page as string | number, {
|
|
18
|
+
min: 1,
|
|
19
|
+
clamp: true
|
|
20
|
+
}) ?? 1;
|
|
21
|
+
|
|
22
|
+
const pageSize = coerce.integer(q.pageSize as string | number, {
|
|
23
|
+
min: 1,
|
|
24
|
+
max: maxPageSize,
|
|
25
|
+
clamp: true
|
|
26
|
+
}) ?? defaultPageSize;
|
|
27
|
+
|
|
28
|
+
return { page, pageSize };
|
|
29
|
+
}
|