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

Function searchEntries

packages/query-devtools/src/explorerSearch.ts:58–105  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

56 * @returns Original entries, or undefined for opaque values.
57 */
58export function searchEntries(value: unknown): Array<SearchEntry> | undefined {
59 try {
60 if (
61 value === null ||
62 typeof value !== 'object' ||
63 ArrayBuffer.isView(value)
64 ) {
65 return undefined
66 }
67 const type = getNativeObjectType(value)
68 if (type === 'String') return undefined
69 if (type === 'Map') {
70 return Array.from(Map.prototype.entries.call(value), ([key, entry]) => ({
71 key,
72 label: primitiveText(key) ?? '[Object key]',
73 value: entry,
74 }))
75 }
76 if (type === 'Set') {
77 return Array.from(Set.prototype.values.call(value), (entry, index) => ({
78 key: String(index),
79 label: String(index),
80 value: entry,
81 }))
82 }
83 const entries = Object.entries(Object.getOwnPropertyDescriptors(value))
84 .filter(([, descriptor]) => descriptor.enumerable)
85 .map(([key, descriptor]) => ({
86 key,
87 label: key,
88 value: descriptor.value,
89 accessor: !('value' in descriptor),
90 }))
91 if (
92 !Array.isArray(value) &&
93 Object.getPrototypeOf(value) !== Object.prototype &&
94 Object.getPrototypeOf(value) !== null &&
95 !entries.some(
96 (entry) => !entry.accessor && typeof entry.value !== 'function',
97 )
98 ) {
99 return undefined
100 }
101 return entries
102 } catch {
103 return undefined
104 }
105}
106
107// `toLowerCase` never outputs it, so a lowercased term can't match across two joined parts
108const SEARCH_TEXT_SEPARATOR = 'A'

Callers 4

ExplorerFunction · 0.90
createSearchTextFunction · 0.85
visitFunction · 0.85

Calls 2

getNativeObjectTypeFunction · 0.90
primitiveTextFunction · 0.85

Tested by

no test coverage detected