File tree Expand file tree Collapse file tree 7 files changed +40
-20
lines changed Expand file tree Collapse file tree 7 files changed +40
-20
lines changed Original file line number Diff line number Diff line change @@ -1331,10 +1331,15 @@ class RequestBuilder {
1331
1331
return this ;
1332
1332
}
1333
1333
withSort ( sort ) {
1334
- this . requestOptions . sort = sort . map ( ( sortOption ) => ( {
1335
- key : sortOption . key ,
1336
- direction : sortOption . direction || "asc"
1337
- } ) ) ;
1334
+ this . requestOptions . sort = sort . map ( ( sortOption ) => {
1335
+ if ( sortOption . direction && sortOption . direction !== "asc" && sortOption . direction !== "desc" ) {
1336
+ throw new Error ( `Sort direction must be either 'asc' or 'desc', got: ${ sortOption . direction } ` ) ;
1337
+ }
1338
+ return {
1339
+ key : sortOption . key ,
1340
+ direction : sortOption . direction
1341
+ } ;
1342
+ } ) ;
1338
1343
return this ;
1339
1344
}
1340
1345
withFilters ( filters ) {
Original file line number Diff line number Diff line change 1
1
import { RequestOptions } from "../utils/RequestOptions" ;
2
- import type { RequestOptionsType } from "../utils/RequestOptions" ;
2
+ import type { RequestOptionsType , SortDirection } from "../utils/RequestOptions" ;
3
3
export declare class RequestBuilder {
4
4
protected requestOptions : RequestOptionsType ;
5
5
withIncludes ( includes : string [ ] ) : this;
6
6
withSort ( sort : Array < {
7
7
key : string ;
8
- direction ?: 'asc' | 'desc' ;
8
+ direction ?: SortDirection ;
9
9
} > ) : this;
10
10
withFilters ( filters : Array < {
11
11
key : string ;
Original file line number Diff line number Diff line change @@ -6,10 +6,15 @@ export class RequestBuilder {
6
6
return this ;
7
7
}
8
8
withSort ( sort ) {
9
- this . requestOptions . sort = sort . map ( sortOption => ( {
10
- key : sortOption . key ,
11
- direction : sortOption . direction || 'asc'
12
- } ) ) ;
9
+ this . requestOptions . sort = sort . map ( sortOption => {
10
+ if ( sortOption . direction && sortOption . direction !== 'asc' && sortOption . direction !== 'desc' ) {
11
+ throw new Error ( `Sort direction must be either 'asc' or 'desc', got: ${ sortOption . direction } ` ) ;
12
+ }
13
+ return {
14
+ key : sortOption . key ,
15
+ direction : sortOption . direction
16
+ } ;
17
+ } ) ;
13
18
return this ;
14
19
}
15
20
withFilters ( filters ) {
Original file line number Diff line number Diff line change
1
+ export type SortDirection = 'asc' | 'desc' | string ;
1
2
type Sort = {
2
3
key : string ;
3
- direction ?: 'asc' | 'desc' ;
4
+ direction ?: SortDirection ;
4
5
} ;
5
6
type Filter = {
6
7
key : string ;
Original file line number Diff line number Diff line change 4
4
"type" : " git" ,
5
5
"url" : " https://github.com/ctrl-hub/sdk.ts"
6
6
},
7
- "version" : " 0.1.134 " ,
7
+ "version" : " 0.1.135 " ,
8
8
"main" : " dist/index.js" ,
9
9
"types" : " dist/index.d.ts" ,
10
10
"type" : " module" ,
Original file line number Diff line number Diff line change 1
1
import { RequestOptions } from "../utils/RequestOptions" ;
2
- import type { RequestOptionsType } from "../utils/RequestOptions" ;
2
+ import type { RequestOptionsType , SortDirection } from "../utils/RequestOptions" ;
3
3
4
4
export class RequestBuilder {
5
5
protected requestOptions : RequestOptionsType = { } ;
@@ -9,11 +9,18 @@ export class RequestBuilder {
9
9
return this ;
10
10
}
11
11
12
- withSort ( sort : Array < { key : string , direction ?: 'asc' | 'desc' } > ) : this {
13
- this . requestOptions . sort = sort . map ( sortOption => ( {
14
- key : sortOption . key ,
15
- direction : sortOption . direction || 'asc'
16
- } ) ) ;
12
+ withSort ( sort : Array < { key : string , direction ?: SortDirection } > ) : this {
13
+ this . requestOptions . sort = sort . map ( sortOption => {
14
+
15
+ if ( sortOption . direction && sortOption . direction !== 'asc' && sortOption . direction !== 'desc' ) {
16
+ throw new Error ( `Sort direction must be either 'asc' or 'desc', got: ${ sortOption . direction } ` ) ;
17
+ }
18
+
19
+ return {
20
+ key : sortOption . key ,
21
+ direction : sortOption . direction
22
+ } ;
23
+ } ) ;
17
24
return this ;
18
25
}
19
26
Original file line number Diff line number Diff line change
1
+ export type SortDirection = 'asc' | 'desc' | string ;
2
+
1
3
type Sort = {
2
4
key : string ;
3
- direction ?: 'asc' | 'desc' ;
5
+ direction ?: SortDirection ;
4
6
} ;
5
7
6
8
type Filter = {
@@ -115,4 +117,4 @@ export class RequestOptions {
115
117
116
118
return requestOptions ;
117
119
}
118
- }
120
+ }
You can’t perform that action at this time.
0 commit comments