@tanstack/query-devtools 5.105.2 → 5.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/Devtools-C6d4y1zP.js +1270 -0
- package/build/Devtools-C6d4y1zP.js.map +1 -0
- package/build/{Devtools-DICxXjAp.js → Devtools-DN7p-sdp.js} +2866 -524
- package/build/{Devtools-2V_Pd-w1.cjs → Devtools-DwGQtvng.cjs} +2844 -502
- package/build/Devtools-he_mAvFk.cjs +1269 -0
- package/build/{DevtoolsComponent-CLOdqERu.js → DevtoolsComponent-CJQXyYNJ.js} +3 -2
- package/build/DevtoolsComponent-D4pZpbHT.cjs +2 -0
- package/build/{DevtoolsComponent-BAslf3AU.cjs → DevtoolsComponent-D8sLZqb7.cjs} +3 -2
- package/build/{DevtoolsComponent-D1MmpObN.js → DevtoolsComponent-DQLY23gz.js} +3 -2
- package/build/{DevtoolsComponent-D1MmpObN.js.map → DevtoolsComponent-DQLY23gz.js.map} +1 -1
- package/build/DevtoolsPanelComponent-BLDfq2ww.cjs +2 -0
- package/build/{DevtoolsPanelComponent-BZiLbaMl.js → DevtoolsPanelComponent-CXpcIZT1.js} +3 -2
- package/build/{DevtoolsPanelComponent-CRFy_L77.js → DevtoolsPanelComponent-CmWcNhgP.js} +3 -2
- package/build/{DevtoolsPanelComponent-CRFy_L77.js.map → DevtoolsPanelComponent-CmWcNhgP.js.map} +1 -1
- package/build/{DevtoolsPanelComponent-BIzP-MqF.cjs → DevtoolsPanelComponent-Dpyndu31.cjs} +3 -2
- package/build/dev.cjs +4 -3
- package/build/dev.js +4 -3
- package/build/index.cjs +2 -1
- package/build/index.d.cts +1 -0
- package/build/index.d.cts.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/{utils-CiEaQT28.cjs → utils-CzP8C7c0.cjs} +170 -51
- package/build/{utils-CsIEjnKb.js → utils-D7iZi04l.js} +147 -52
- package/build/utils-DC2pN79q.js +3 -0
- package/build/utils-DC2pN79q.js.map +1 -0
- package/build/utils-DJl-N7L2.cjs +2 -0
- package/package.json +4 -3
- package/src/Devtools.tsx +75 -165
- package/src/Explorer.tsx +349 -28
- package/src/VirtualList.tsx +105 -0
- package/src/explorerSearch.ts +159 -0
- package/src/nativeObjectType.ts +70 -0
- package/src/utils.tsx +74 -34
- package/build/Devtools-CD2ZvU1I.js +0 -1238
- package/build/Devtools-CD2ZvU1I.js.map +0 -1
- package/build/Devtools-DDcV5oIp.cjs +0 -1237
- package/build/DevtoolsComponent-zpIDe7Wu.cjs +0 -1
- package/build/DevtoolsPanelComponent-DJuL4CDS.cjs +0 -1
- package/build/utils-CpoIvKO8.cjs +0 -1
- package/build/utils-LNrmpo6y.js +0 -2
- package/build/utils-LNrmpo6y.js.map +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { getNativeObjectType } from './nativeObjectType'
|
|
2
|
+
|
|
3
|
+
/** Match metadata at one original data path. */
|
|
4
|
+
export type SearchMatch = {
|
|
5
|
+
/** Whether the original entry label matches. */
|
|
6
|
+
label: boolean
|
|
7
|
+
/** Whether a primitive value matches. */
|
|
8
|
+
value: boolean
|
|
9
|
+
/** Includes descendants, so rendering never needs to search a subtree again. */
|
|
10
|
+
hasMatch: boolean
|
|
11
|
+
/** Controls safe expansion and terminal display during search. */
|
|
12
|
+
kind: 'branch' | 'value' | 'opaque' | 'circular' | 'accessor'
|
|
13
|
+
/** Entries keyed by their original label, including Map key identity. */
|
|
14
|
+
children: ReadonlyMap<unknown, SearchMatch>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Search information passed to an individual explorer row. */
|
|
18
|
+
export type ExplorerSearch = {
|
|
19
|
+
/** The case-normalized literal search term. */
|
|
20
|
+
term: string
|
|
21
|
+
/** Match metadata for this row's original data path. */
|
|
22
|
+
match: SearchMatch
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type SearchEntry = {
|
|
26
|
+
key: unknown
|
|
27
|
+
label: string
|
|
28
|
+
value: unknown
|
|
29
|
+
accessor?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Converts only primitive values to searchable text.
|
|
34
|
+
* @param value - The inspected value.
|
|
35
|
+
* @returns Primitive text, or undefined for objects and functions.
|
|
36
|
+
*/
|
|
37
|
+
export function primitiveText(value: unknown): string | undefined {
|
|
38
|
+
if (value === null) return 'null'
|
|
39
|
+
switch (typeof value) {
|
|
40
|
+
case 'string':
|
|
41
|
+
case 'number':
|
|
42
|
+
case 'boolean':
|
|
43
|
+
case 'bigint':
|
|
44
|
+
case 'symbol':
|
|
45
|
+
case 'undefined':
|
|
46
|
+
return String(value)
|
|
47
|
+
default:
|
|
48
|
+
return undefined
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Reads finite entries through native collection methods and own descriptors.
|
|
54
|
+
* Accessors and user-defined iterators or key conversions are not evaluated.
|
|
55
|
+
* @param value - The inspected value.
|
|
56
|
+
* @returns Original entries, or undefined for opaque values.
|
|
57
|
+
*/
|
|
58
|
+
export 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
|
+
/**
|
|
108
|
+
* Builds one search tree, stopping ancestor cycles while visiting shared siblings.
|
|
109
|
+
* @param rootValue - The current root data.
|
|
110
|
+
* @param term - The case-normalized literal search term.
|
|
111
|
+
* @returns Match and safe rendering metadata for every original entry.
|
|
112
|
+
*/
|
|
113
|
+
export function searchExplorer(rootValue: unknown, term: string): SearchMatch {
|
|
114
|
+
const ancestors = new Set<unknown>()
|
|
115
|
+
/**
|
|
116
|
+
* Visits one original path with its current ancestors.
|
|
117
|
+
* @param value - The entry value.
|
|
118
|
+
* @param label - The entry label; absent for the synthetic root.
|
|
119
|
+
* @param accessor - Whether reading the entry would invoke a getter.
|
|
120
|
+
* @param depth - The current nesting depth.
|
|
121
|
+
* @returns The entry's match metadata.
|
|
122
|
+
*/
|
|
123
|
+
function visit(
|
|
124
|
+
value: unknown,
|
|
125
|
+
label?: string,
|
|
126
|
+
accessor = false,
|
|
127
|
+
depth = 0,
|
|
128
|
+
): SearchMatch {
|
|
129
|
+
const labelMatch = label?.toLowerCase().includes(term) ?? false
|
|
130
|
+
const text = accessor ? undefined : primitiveText(value)
|
|
131
|
+
const valueMatch = text?.toLowerCase().includes(term) ?? false
|
|
132
|
+
const children = new Map<unknown, SearchMatch>()
|
|
133
|
+
const match: SearchMatch = {
|
|
134
|
+
label: labelMatch,
|
|
135
|
+
value: valueMatch,
|
|
136
|
+
hasMatch: labelMatch || valueMatch,
|
|
137
|
+
kind: accessor ? 'accessor' : text !== undefined ? 'value' : 'opaque',
|
|
138
|
+
children,
|
|
139
|
+
}
|
|
140
|
+
if (accessor || text !== undefined) return match
|
|
141
|
+
if (depth > 500) return match
|
|
142
|
+
if (ancestors.has(value)) {
|
|
143
|
+
match.kind = 'circular'
|
|
144
|
+
return match
|
|
145
|
+
}
|
|
146
|
+
const entries = searchEntries(value)
|
|
147
|
+
if (!entries) return match
|
|
148
|
+
match.kind = 'branch'
|
|
149
|
+
ancestors.add(value)
|
|
150
|
+
for (const entry of entries) {
|
|
151
|
+
const child = visit(entry.value, entry.label, entry.accessor, depth + 1)
|
|
152
|
+
children.set(entry.key, child)
|
|
153
|
+
match.hasMatch ||= child.hasMatch
|
|
154
|
+
}
|
|
155
|
+
ancestors.delete(value)
|
|
156
|
+
return match
|
|
157
|
+
}
|
|
158
|
+
return visit(rootValue)
|
|
159
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
type NativeObjectType = 'Map' | 'Set' | 'String'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks an object's internal slots with an intrinsic operation.
|
|
5
|
+
* @param value - The inspected object.
|
|
6
|
+
* @param type - The native brand to check.
|
|
7
|
+
* @returns Whether the intrinsic operation accepts the object.
|
|
8
|
+
*/
|
|
9
|
+
function hasNativeBrand(value: object, type: NativeObjectType): boolean {
|
|
10
|
+
try {
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'Map':
|
|
13
|
+
Map.prototype.has.call(value, undefined)
|
|
14
|
+
return true
|
|
15
|
+
case 'Set':
|
|
16
|
+
Set.prototype.has.call(value, undefined)
|
|
17
|
+
return true
|
|
18
|
+
case 'String':
|
|
19
|
+
String.prototype.valueOf.call(value)
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Identifies native collections and String wrappers across realms without reading accessors.
|
|
29
|
+
* @param value - The inspected value.
|
|
30
|
+
* @returns Its native brand, or undefined for other values and failed inspections.
|
|
31
|
+
*/
|
|
32
|
+
export function getNativeObjectType(
|
|
33
|
+
value: unknown,
|
|
34
|
+
): NativeObjectType | undefined {
|
|
35
|
+
if (value === null || typeof value !== 'object') return undefined
|
|
36
|
+
try {
|
|
37
|
+
if (Array.isArray(value) || ArrayBuffer.isView(value)) return undefined
|
|
38
|
+
const length = Object.getOwnPropertyDescriptor(value, 'length')
|
|
39
|
+
if (
|
|
40
|
+
typeof length?.value === 'number' &&
|
|
41
|
+
!length.enumerable &&
|
|
42
|
+
!length.writable &&
|
|
43
|
+
!length.configurable &&
|
|
44
|
+
hasNativeBrand(value, 'String')
|
|
45
|
+
) {
|
|
46
|
+
return 'String'
|
|
47
|
+
}
|
|
48
|
+
const parent = Object.getPrototypeOf(value)
|
|
49
|
+
if (parent === null) {
|
|
50
|
+
if (hasNativeBrand(value, 'Map')) return 'Map'
|
|
51
|
+
if (hasNativeBrand(value, 'Set')) return 'Set'
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
if (parent === Object.prototype) return undefined
|
|
55
|
+
let prototype: object | null = value
|
|
56
|
+
for (let depth = 0; prototype && depth <= 500; depth++) {
|
|
57
|
+
const tag = Object.getOwnPropertyDescriptor(
|
|
58
|
+
prototype,
|
|
59
|
+
Symbol.toStringTag,
|
|
60
|
+
)?.value
|
|
61
|
+
if ((tag === 'Map' || tag === 'Set') && hasNativeBrand(value, tag)) {
|
|
62
|
+
return tag
|
|
63
|
+
}
|
|
64
|
+
prototype = Object.getPrototypeOf(prototype)
|
|
65
|
+
}
|
|
66
|
+
return undefined
|
|
67
|
+
} catch {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/utils.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { serialize } from 'superjson'
|
|
2
2
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
|
3
|
+
import { getNativeObjectType } from './nativeObjectType'
|
|
3
4
|
import type { Mutation, Query } from '@tanstack/query-core'
|
|
4
5
|
import type { DevtoolsPosition } from './contexts'
|
|
5
6
|
|
|
@@ -207,6 +208,32 @@ export const getPreferredColorScheme = () => {
|
|
|
207
208
|
return colorScheme
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Checks whether a value is a plain object without invoking accessors, including across realms.
|
|
213
|
+
* @param value - The data to inspect.
|
|
214
|
+
* @returns Whether the value can be copied as a record.
|
|
215
|
+
*/
|
|
216
|
+
export function isPlainObject(value: unknown): boolean {
|
|
217
|
+
if (value === null || typeof value !== 'object') return false
|
|
218
|
+
try {
|
|
219
|
+
const prototype = Object.getPrototypeOf(value)
|
|
220
|
+
if (prototype === null) return true
|
|
221
|
+
const constructor = Object.getOwnPropertyDescriptor(
|
|
222
|
+
prototype,
|
|
223
|
+
'constructor',
|
|
224
|
+
)?.value
|
|
225
|
+
return (
|
|
226
|
+
typeof constructor === 'function' &&
|
|
227
|
+
Object.getOwnPropertyDescriptor(constructor, 'prototype')?.value ===
|
|
228
|
+
prototype &&
|
|
229
|
+
Function.prototype.toString.call(constructor) ===
|
|
230
|
+
Function.prototype.toString.call(Object)
|
|
231
|
+
)
|
|
232
|
+
} catch {
|
|
233
|
+
return false
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
210
237
|
/**
|
|
211
238
|
* Updates nested data by path.
|
|
212
239
|
* @param oldData - Data to be updated
|
|
@@ -223,8 +250,11 @@ export const updateNestedDataByPath = (
|
|
|
223
250
|
return value
|
|
224
251
|
}
|
|
225
252
|
|
|
226
|
-
|
|
227
|
-
|
|
253
|
+
const type = getNativeObjectType(oldData)
|
|
254
|
+
if (type === 'Map') {
|
|
255
|
+
const newData = new Map<unknown, unknown>(
|
|
256
|
+
Map.prototype.entries.call(oldData),
|
|
257
|
+
)
|
|
228
258
|
|
|
229
259
|
if (updatePath.length === 1) {
|
|
230
260
|
newData.set(updatePath[0], value)
|
|
@@ -236,9 +266,9 @@ export const updateNestedDataByPath = (
|
|
|
236
266
|
return newData
|
|
237
267
|
}
|
|
238
268
|
|
|
239
|
-
if (
|
|
269
|
+
if (type === 'Set') {
|
|
240
270
|
const setAsArray = updateNestedDataByPath(
|
|
241
|
-
Array.from(oldData),
|
|
271
|
+
Array.from(Set.prototype.values.call(oldData)),
|
|
242
272
|
updatePath,
|
|
243
273
|
value,
|
|
244
274
|
)
|
|
@@ -262,20 +292,23 @@ export const updateNestedDataByPath = (
|
|
|
262
292
|
return newData
|
|
263
293
|
}
|
|
264
294
|
|
|
265
|
-
if (oldData
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
if (updatePath.length === 1) {
|
|
269
|
-
// @ts-expect-error
|
|
270
|
-
newData[updatePath[0]] = value
|
|
271
|
-
return newData
|
|
272
|
-
}
|
|
273
|
-
|
|
295
|
+
if (isPlainObject(oldData)) {
|
|
296
|
+
const descriptors = Object.getOwnPropertyDescriptors(oldData)
|
|
274
297
|
const [head, ...tail] = updatePath
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return
|
|
298
|
+
if (head === undefined) return oldData
|
|
299
|
+
const previous = Object.getOwnPropertyDescriptor(oldData, head)
|
|
300
|
+
if (tail.length && (!previous || !('value' in previous))) return oldData
|
|
301
|
+
return Object.create(Object.getPrototypeOf(oldData), {
|
|
302
|
+
...descriptors,
|
|
303
|
+
[head]: {
|
|
304
|
+
value: tail.length
|
|
305
|
+
? updateNestedDataByPath(previous?.value, tail, value)
|
|
306
|
+
: value,
|
|
307
|
+
enumerable: previous?.enumerable ?? true,
|
|
308
|
+
configurable: true,
|
|
309
|
+
writable: true,
|
|
310
|
+
},
|
|
311
|
+
})
|
|
279
312
|
}
|
|
280
313
|
|
|
281
314
|
return oldData
|
|
@@ -291,8 +324,11 @@ export const deleteNestedDataByPath = (
|
|
|
291
324
|
oldData: unknown,
|
|
292
325
|
deletePath: Array<string>,
|
|
293
326
|
): any => {
|
|
294
|
-
|
|
295
|
-
|
|
327
|
+
const type = getNativeObjectType(oldData)
|
|
328
|
+
if (type === 'Map') {
|
|
329
|
+
const newData = new Map<unknown, unknown>(
|
|
330
|
+
Map.prototype.entries.call(oldData),
|
|
331
|
+
)
|
|
296
332
|
|
|
297
333
|
if (deletePath.length === 1) {
|
|
298
334
|
newData.delete(deletePath[0])
|
|
@@ -304,8 +340,11 @@ export const deleteNestedDataByPath = (
|
|
|
304
340
|
return newData
|
|
305
341
|
}
|
|
306
342
|
|
|
307
|
-
if (
|
|
308
|
-
const setAsArray = deleteNestedDataByPath(
|
|
343
|
+
if (type === 'Set') {
|
|
344
|
+
const setAsArray = deleteNestedDataByPath(
|
|
345
|
+
Array.from(Set.prototype.values.call(oldData)),
|
|
346
|
+
deletePath,
|
|
347
|
+
)
|
|
309
348
|
return new Set(setAsArray)
|
|
310
349
|
}
|
|
311
350
|
|
|
@@ -324,20 +363,21 @@ export const deleteNestedDataByPath = (
|
|
|
324
363
|
return newData
|
|
325
364
|
}
|
|
326
365
|
|
|
327
|
-
if (oldData
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
if (deletePath.length === 1) {
|
|
331
|
-
// @ts-expect-error
|
|
332
|
-
delete newData[deletePath[0]]
|
|
333
|
-
return newData
|
|
334
|
-
}
|
|
335
|
-
|
|
366
|
+
if (isPlainObject(oldData)) {
|
|
367
|
+
const descriptors = Object.getOwnPropertyDescriptors(oldData)
|
|
336
368
|
const [head, ...tail] = deletePath
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
369
|
+
if (head === undefined) return oldData
|
|
370
|
+
if (tail.length === 0) {
|
|
371
|
+
delete descriptors[head]
|
|
372
|
+
} else {
|
|
373
|
+
const previous = Object.getOwnPropertyDescriptor(oldData, head)
|
|
374
|
+
if (!previous || !('value' in previous)) return oldData
|
|
375
|
+
descriptors[head] = {
|
|
376
|
+
...previous,
|
|
377
|
+
value: deleteNestedDataByPath(previous.value, tail),
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return Object.create(Object.getPrototypeOf(oldData), descriptors)
|
|
341
381
|
}
|
|
342
382
|
|
|
343
383
|
return oldData
|