MCPcopy Create free account
hub / github.com/developmentseed/stac-react / extractSearchParams

Function extractSearchParams

src/utils/queryKeys.ts:9–37  ·  view source on GitHub ↗

* Extracts only the essential search parameters from a payload for query key generation. * This creates a minimal, stable key that's cheap to hash. * Handles both dateRange (from useStacSearch state) and datetime (from API transformations). * Also includes pagination-specific parameters (token, p

(payload: SearchRequestPayload)

Source from the content-addressed store, hash-verified

7 * Also includes pagination-specific parameters (token, page, merge) that make requests unique.
8 */
9function extractSearchParams(payload: SearchRequestPayload): Record<string, unknown> {
10 const params: Record<string, unknown> = {};
11
12 // Only include defined search parameters
13 if (payload.ids !== undefined) params.ids = payload.ids;
14 if (payload.bbox !== undefined) params.bbox = payload.bbox;
15 if (payload.collections !== undefined) params.collections = payload.collections;
16
17 // Handle both dateRange (from hook state) and datetime (from API transformation)
18 if (payload.datetime !== undefined) {
19 params.datetime = payload.datetime;
20 } else if (payload.dateRange !== undefined) {
21 // Convert dateRange to datetime format for consistent keys
22 const { from, to } = payload.dateRange;
23 if (from || to) {
24 params.datetime = `${from || '..'}/${to || '..'}`;
25 }
26 }
27
28 if (payload.sortby !== undefined) params.sortby = payload.sortby;
29 if (payload.limit !== undefined) params.limit = payload.limit;
30
31 // Include pagination-specific parameters
32 if (payload.token !== undefined) params.token = payload.token;
33 if (payload.page !== undefined) params.page = payload.page;
34 if (payload.merge !== undefined) params.merge = payload.merge;
35
36 return params;
37}
38
39/**
40 * Generates a query key for STAC collections requests.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected