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 {
13311331 return this ;
13321332 }
13331333 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+ } ) ;
13381343 return this ;
13391344 }
13401345 withFilters ( filters ) {
Original file line number Diff line number Diff line change 11import { RequestOptions } from "../utils/RequestOptions" ;
2- import type { RequestOptionsType } from "../utils/RequestOptions" ;
2+ import type { RequestOptionsType , SortDirection } from "../utils/RequestOptions" ;
33export declare class RequestBuilder {
44 protected requestOptions : RequestOptionsType ;
55 withIncludes ( includes : string [ ] ) : this;
66 withSort ( sort : Array < {
77 key : string ;
8- direction ?: 'asc' | 'desc' ;
8+ direction ?: SortDirection ;
99 } > ) : this;
1010 withFilters ( filters : Array < {
1111 key : string ;
Original file line number Diff line number Diff line change @@ -6,10 +6,15 @@ export class RequestBuilder {
66 return this ;
77 }
88 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+ } ) ;
1318 return this ;
1419 }
1520 withFilters ( filters ) {
Original file line number Diff line number Diff line change 1+ export type SortDirection = 'asc' | 'desc' | string ;
12type Sort = {
23 key : string ;
3- direction ?: 'asc' | 'desc' ;
4+ direction ?: SortDirection ;
45} ;
56type Filter = {
67 key : string ;
Original file line number Diff line number Diff line change 44 "type" : " git" ,
55 "url" : " https://github.com/ctrl-hub/sdk.ts"
66 },
7- "version" : " 0.1.134 " ,
7+ "version" : " 0.1.135 " ,
88 "main" : " dist/index.js" ,
99 "types" : " dist/index.d.ts" ,
1010 "type" : " module" ,
Original file line number Diff line number Diff line change 11import { RequestOptions } from "../utils/RequestOptions" ;
2- import type { RequestOptionsType } from "../utils/RequestOptions" ;
2+ import type { RequestOptionsType , SortDirection } from "../utils/RequestOptions" ;
33
44export class RequestBuilder {
55 protected requestOptions : RequestOptionsType = { } ;
@@ -9,11 +9,18 @@ export class RequestBuilder {
99 return this ;
1010 }
1111
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+ } ) ;
1724 return this ;
1825 }
1926
Original file line number Diff line number Diff line change 1+ export type SortDirection = 'asc' | 'desc' | string ;
2+
13type Sort = {
24 key : string ;
3- direction ?: 'asc' | 'desc' ;
5+ direction ?: SortDirection ;
46} ;
57
68type Filter = {
@@ -115,4 +117,4 @@ export class RequestOptions {
115117
116118 return requestOptions ;
117119 }
118- }
120+ }
You can’t perform that action at this time.
0 commit comments