-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathquery.ts
More file actions
28 lines (20 loc) · 788 Bytes
/
query.ts
File metadata and controls
28 lines (20 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { ListModels } from "../interface/List";
/**
* Build the path for `list/models` with proper query-string encoding.
*
* Isolated into a pure function for:
* - Unit testability without mocking HTTP
* - Clear separation of concerns (URL construction vs. network)
* - Easy reasoning about edge cases
*/
export function buildListModelsPath(options?: ListModels): string {
const base = "list/models";
if (!options) return base;
const params: Record<string, string> = {};
if (options.task) params.task = String(options.task);
if (options.modelId) params.modelId = String(options.modelId);
const entries = Object.entries(params);
if (entries.length === 0) return base;
const search = new URLSearchParams(entries).toString();
return `${base}?${search}`;
}