MCPcopy Create free account
hub / github.com/TanStack/query / createSearchText

Function createSearchText

packages/query-devtools/src/explorerSearch.ts:118–145  ·  view source on GitHub ↗
(rootValue: unknown)

Source from the content-addressed store, hash-verified

116 * @returns Text that contains a lowercased term exactly when `searchExplorer` matches it.
117 */
118export function createSearchText(rootValue: unknown): string {
119 const rootText = primitiveText(rootValue)
120 if (rootText !== undefined) return rootText.toLowerCase()
121 const parts: Array<string> = []
122 const seen = new Set<unknown>([rootValue])
123 const queue: Array<{ value: unknown; depth: number }> = [
124 { value: rootValue, depth: 0 },
125 ]
126 // Also visits the entries pushed while iterating
127 for (const { value, depth } of queue) {
128 for (const entry of searchEntries(value) ?? []) {
129 parts.push(entry.label.toLowerCase())
130 if (entry.accessor) continue
131 const text = primitiveText(entry.value)
132 if (text !== undefined) {
133 parts.push(text.toLowerCase())
134 } else if (
135 depth < 500 &&
136 typeof entry.value === 'object' &&
137 !seen.has(entry.value)
138 ) {
139 seen.add(entry.value)
140 queue.push({ value: entry.value, depth: depth + 1 })
141 }
142 }
143 }
144 return parts.join(SEARCH_TEXT_SEPARATOR)
145}
146
147/**
148 * Builds one search tree, stopping ancestor cycles while visiting shared siblings.

Callers 3

getDataSearchTextFunction · 0.90
matchesFunction · 0.90

Calls 3

primitiveTextFunction · 0.85
searchEntriesFunction · 0.85
addMethod · 0.45

Tested by 1

matchesFunction · 0.72