smart-query-nestjs 1.0.3 → 1.0.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.
@@ -0,0 +1,72 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler, DynamicModule } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+
4
+ interface SmartQueryConfig {
5
+ searchableFields: string[];
6
+ filterableFields: string[];
7
+ numberFields?: string[];
8
+ booleanFields?: string[];
9
+ dateFields?: string[];
10
+ defaultLimit?: number;
11
+ maxLimit?: number;
12
+ }
13
+
14
+ interface PaginationOptions {
15
+ page: number;
16
+ limit: number;
17
+ skip: number;
18
+ sortBy: string;
19
+ sortOrder: 'asc' | 'desc';
20
+ }
21
+
22
+ interface SmartQueryContext {
23
+ where: Record<string, unknown>;
24
+ pagination: PaginationOptions;
25
+ }
26
+
27
+ declare function parseQueryString(queryString: string): Record<string, unknown>;
28
+
29
+ declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
30
+
31
+ interface SearchCondition {
32
+ OR: Record<string, {
33
+ contains: string;
34
+ mode: string;
35
+ }>[];
36
+ }
37
+ declare function buildSearchConditions(searchTerm: string | undefined, config: SmartQueryConfig): SearchCondition | null;
38
+
39
+ declare function parseFilters(query: Record<string, unknown>, config: SmartQueryConfig): Record<string, unknown>;
40
+
41
+ declare function parsePagination(query: Record<string, unknown>, config: SmartQueryConfig): PaginationOptions;
42
+
43
+ declare const SMART_QUERY_CONFIG = "SMART_QUERY_CONFIG";
44
+ declare class SmartQueryInterceptor implements NestInterceptor {
45
+ private readonly config;
46
+ constructor(config: SmartQueryConfig);
47
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
48
+ }
49
+ declare function createSmartQueryInterceptor(config: SmartQueryConfig): SmartQueryInterceptor;
50
+
51
+ declare const SmartQuery: (...dataOrPipes: unknown[]) => ParameterDecorator;
52
+
53
+ interface BuildSmartQueryOptions {
54
+ where?: Record<string, unknown>;
55
+ orderBy?: Record<string, 'asc' | 'desc'>;
56
+ skip?: number;
57
+ take?: number;
58
+ }
59
+ interface SmartQueryResult {
60
+ where: Record<string, unknown>;
61
+ orderBy: Record<string, 'asc' | 'desc'>;
62
+ skip: number;
63
+ take: number;
64
+ page: number;
65
+ }
66
+ declare function buildSmartQuery(context: SmartQueryContext, ...extraConditions: Record<string, unknown>[]): SmartQueryResult;
67
+
68
+ declare class SmartQueryModule {
69
+ static forRoot(config: SmartQueryConfig): DynamicModule;
70
+ }
71
+
72
+ export { type BuildSmartQueryOptions, type PaginationOptions, SMART_QUERY_CONFIG, SmartQuery, type SmartQueryConfig, type SmartQueryContext, SmartQueryInterceptor, SmartQueryModule, type SmartQueryResult, buildSearchConditions, buildSmartQuery, createSmartQueryInterceptor, parseFilters, parsePagination, parseQueryString, pick };
@@ -0,0 +1,72 @@
1
+ import { NestInterceptor, ExecutionContext, CallHandler, DynamicModule } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+
4
+ interface SmartQueryConfig {
5
+ searchableFields: string[];
6
+ filterableFields: string[];
7
+ numberFields?: string[];
8
+ booleanFields?: string[];
9
+ dateFields?: string[];
10
+ defaultLimit?: number;
11
+ maxLimit?: number;
12
+ }
13
+
14
+ interface PaginationOptions {
15
+ page: number;
16
+ limit: number;
17
+ skip: number;
18
+ sortBy: string;
19
+ sortOrder: 'asc' | 'desc';
20
+ }
21
+
22
+ interface SmartQueryContext {
23
+ where: Record<string, unknown>;
24
+ pagination: PaginationOptions;
25
+ }
26
+
27
+ declare function parseQueryString(queryString: string): Record<string, unknown>;
28
+
29
+ declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
30
+
31
+ interface SearchCondition {
32
+ OR: Record<string, {
33
+ contains: string;
34
+ mode: string;
35
+ }>[];
36
+ }
37
+ declare function buildSearchConditions(searchTerm: string | undefined, config: SmartQueryConfig): SearchCondition | null;
38
+
39
+ declare function parseFilters(query: Record<string, unknown>, config: SmartQueryConfig): Record<string, unknown>;
40
+
41
+ declare function parsePagination(query: Record<string, unknown>, config: SmartQueryConfig): PaginationOptions;
42
+
43
+ declare const SMART_QUERY_CONFIG = "SMART_QUERY_CONFIG";
44
+ declare class SmartQueryInterceptor implements NestInterceptor {
45
+ private readonly config;
46
+ constructor(config: SmartQueryConfig);
47
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
48
+ }
49
+ declare function createSmartQueryInterceptor(config: SmartQueryConfig): SmartQueryInterceptor;
50
+
51
+ declare const SmartQuery: (...dataOrPipes: unknown[]) => ParameterDecorator;
52
+
53
+ interface BuildSmartQueryOptions {
54
+ where?: Record<string, unknown>;
55
+ orderBy?: Record<string, 'asc' | 'desc'>;
56
+ skip?: number;
57
+ take?: number;
58
+ }
59
+ interface SmartQueryResult {
60
+ where: Record<string, unknown>;
61
+ orderBy: Record<string, 'asc' | 'desc'>;
62
+ skip: number;
63
+ take: number;
64
+ page: number;
65
+ }
66
+ declare function buildSmartQuery(context: SmartQueryContext, ...extraConditions: Record<string, unknown>[]): SmartQueryResult;
67
+
68
+ declare class SmartQueryModule {
69
+ static forRoot(config: SmartQueryConfig): DynamicModule;
70
+ }
71
+
72
+ export { type BuildSmartQueryOptions, type PaginationOptions, SMART_QUERY_CONFIG, SmartQuery, type SmartQueryConfig, type SmartQueryContext, SmartQueryInterceptor, SmartQueryModule, type SmartQueryResult, buildSearchConditions, buildSmartQuery, createSmartQueryInterceptor, parseFilters, parsePagination, parseQueryString, pick };