MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / validateSort

Function validateSort

js/botasaurus-server-js/src/validation.ts:219–237  ·  view source on GitHub ↗
(jsonData: any, allowedSorts: string[], defaultSort: string)

Source from the content-addressed store, hash-verified

217}
218
219export function validateSort(jsonData: any, allowedSorts: string[], defaultSort: string): string | null {
220 let sort = jsonData.sort ?? defaultSort;
221
222 if (sort === 'no_sort' || isEmpty(sort)) {
223 sort = null;
224 } else if (isNotNullish(sort)) {
225 if (!isStringOfMinLength(sort)) {
226 throw new JsonHTTPResponseWithMessage('Sort must be a string with at least one character');
227 }
228
229 sort = sort.toLowerCase();
230 if (!allowedSorts.includes(sort)) {
231 throw new JsonHTTPResponseWithMessage(`Invalid sort. Must be one of: ${allowedSorts.join(', ')}.`);
232 }
233 } else {
234 sort = defaultSort;
235 }
236 return sort;
237}
238
239export function validateResultsRequest(jsonData: any, allowedSorts: string[], allowedViews: string[], defaultSort: string): [any, string | null, string | undefined, number, number | undefined] {
240 ensureJsonBodyIsDict(jsonData);

Callers 2

validateResultsRequestFunction · 0.85
validateDownloadParamsFunction · 0.85

Calls 4

isEmptyFunction · 0.90
isNotNullishFunction · 0.90
isStringOfMinLengthFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected