@snap/valdi 1.1.7 → 1.2.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/.metadata/.bazelrc.template +8 -2
- package/.metadata/MODULE.bazel.template +20 -3
- package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
- package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
- package/README.md +35 -1
- package/bundled-skills/registry.json +2 -1
- package/bundled-skills/skills/valdi-animations/skill.md +49 -0
- package/bundled-skills/skills/valdi-async/skill.md +3 -2
- package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
- package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
- package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
- package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
- package/bundled-skills/skills/valdi-overview/skill.md +2 -1
- package/bundled-skills/skills/valdi-perf/skill.md +121 -5
- package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
- package/bundled-skills/skills/valdi-profile/skill.md +5 -3
- package/bundled-skills/skills/valdi-setup/skill.md +3 -6
- package/bundled-skills/skills/valdi-testing/skill.md +1 -1
- package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
- package/debugger/README.md +356 -0
- package/debugger/debugger-actions.js +373 -0
- package/debugger/debugger-api.js +225 -0
- package/debugger/debugger-bootstrap.js +295 -0
- package/debugger/debugger-model.js +790 -0
- package/debugger/debugger-performance.js +573 -0
- package/debugger/debugger-preview-html.js +676 -0
- package/debugger/debugger-providers.js +389 -0
- package/debugger/debugger-render.js +529 -0
- package/debugger/debugger-runtime.js +387 -0
- package/debugger/debugger-session.js +188 -0
- package/debugger/debugger-settings.js +209 -0
- package/debugger/debugger-state.js +221 -0
- package/debugger/debugger-tree-model.js +539 -0
- package/debugger/debugger.css +1865 -0
- package/debugger/devtools-panel.css +1318 -0
- package/debugger/devtools-panel.html +273 -0
- package/debugger/devtools-panel.js +3329 -0
- package/debugger/index.html +279 -0
- package/dist/commands/bootstrap.js +6 -5
- package/dist/commands/debugger.js +163 -0
- package/dist/commands/doctor.js +3 -62
- package/dist/commands/inspect.js +5 -2
- package/dist/commands/inspect_commands/input.js +176 -0
- package/dist/commands/inspect_commands/snapshot.js +1 -1
- package/dist/commands/inspect_commands/tree.js +1 -1
- package/dist/commands/projectsync.js +15 -0
- package/dist/commands/webHotreload.js +31 -0
- package/dist/core/constants.js +22 -6
- package/dist/debugger/chromiumConsole.js +279 -0
- package/dist/debugger/inputClient.js +473 -0
- package/dist/debugger/server.js +3801 -0
- package/dist/debugger/targetRegistry.js +436 -0
- package/dist/debugger/webPreviewPerformance.js +864 -0
- package/dist/index.js +0 -0
- package/dist/utils/BazelClient.js +34 -5
- package/dist/utils/applicationUtils.js +3 -0
- package/dist/utils/chromiumDevToolsClient.js +350 -0
- package/dist/utils/daemonClient.js +364 -44
- package/dist/utils/hermesClient.js +82 -176
- package/dist/utils/loopbackHost.js +14 -0
- package/dist/utils/owlCdpClient.js +282 -0
- package/dist/utils/owlDevToolsExtension.js +142 -0
- package/dist/utils/stringUtils.js +13 -1
- package/package.json +4 -2
- package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
- package/dist/core/packageFiles.spec.js +0 -29
- package/dist/preview/previewGenerator.spec.js +0 -203
- package/dist/preview/viewModelParser.spec.js +0 -171
- package/dist/utils/linuxDistro.spec.js +0 -122
- package/dist/utils/skillsAdapters.spec.js +0 -141
- package/dist/utils/stringUtils.spec.js +0 -81
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
// Transport-neutral Valdi hierarchy helpers shared by standalone and embedded DevTools.
|
|
2
|
+
const MAX_DEBUGGER_TREE_NODES = 25_000;
|
|
3
|
+
const MAX_DEBUGGER_PROJECTION_VALUES = 250_000;
|
|
4
|
+
const MAX_DEBUGGER_PROJECTION_DEPTH = 64;
|
|
5
|
+
const MAX_DEBUGGER_PROJECTION_STRING_LENGTH = 50_000;
|
|
6
|
+
|
|
7
|
+
function debuggerJsonRecord() {
|
|
8
|
+
return Object.create(null);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function setDebuggerJsonProperty(target, key, value) {
|
|
12
|
+
Object.defineProperty(target, key, {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
value,
|
|
16
|
+
writable: true,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function debuggerProjectionTruncation(reason, path) {
|
|
21
|
+
const marker = debuggerJsonRecord();
|
|
22
|
+
setDebuggerJsonProperty(marker, '$at', path);
|
|
23
|
+
setDebuggerJsonProperty(marker, '$truncated', reason);
|
|
24
|
+
return marker;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function markDebuggerProjectionTruncated(target, reason, path) {
|
|
28
|
+
const marker = debuggerProjectionTruncation(reason, path);
|
|
29
|
+
if (Array.isArray(target)) {
|
|
30
|
+
target.push(marker);
|
|
31
|
+
} else if (target.$type === 'array' && Array.isArray(target.$entries)) {
|
|
32
|
+
target.$entries.push(marker);
|
|
33
|
+
} else {
|
|
34
|
+
setDebuggerJsonProperty(target, '$at', marker.$at);
|
|
35
|
+
setDebuggerJsonProperty(target, '$truncated', marker.$truncated);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function debuggerPrimitiveProjection(value, projectionState) {
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
if (value.length <= MAX_DEBUGGER_PROJECTION_STRING_LENGTH) return value;
|
|
42
|
+
projectionState.complete = false;
|
|
43
|
+
const suffix = '…[truncated]';
|
|
44
|
+
return `${value.slice(0, MAX_DEBUGGER_PROJECTION_STRING_LENGTH - suffix.length)}${suffix}`;
|
|
45
|
+
}
|
|
46
|
+
if (value === null || typeof value === 'boolean') return value;
|
|
47
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : String(value);
|
|
48
|
+
if (typeof value === 'bigint') return `${value}n`;
|
|
49
|
+
if (typeof value === 'undefined') return '[undefined]';
|
|
50
|
+
if (typeof value === 'function') return `[Function ${value.name || 'anonymous'}]`;
|
|
51
|
+
if (typeof value === 'symbol') return String(value);
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isDebuggerArrayIndex(key) {
|
|
56
|
+
const index = Number(key);
|
|
57
|
+
return Number.isInteger(index) && index >= 0 && index < 4_294_967_295 && String(index) === key;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function debuggerOwnEntries(source, path, projectionState) {
|
|
61
|
+
let descriptors;
|
|
62
|
+
try {
|
|
63
|
+
descriptors = Object.getOwnPropertyDescriptors(source);
|
|
64
|
+
} catch {
|
|
65
|
+
projectionState.complete = false;
|
|
66
|
+
return { entries: [], inspectionError: debuggerProjectionTruncation('unavailable-properties', path) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const entries = [];
|
|
70
|
+
for (const key of Object.keys(descriptors)) {
|
|
71
|
+
const descriptor = descriptors[key];
|
|
72
|
+
if (!descriptor?.enumerable) continue;
|
|
73
|
+
if (entries.length >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
74
|
+
projectionState.complete = false;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
const childPath = isDebuggerArrayIndex(key) ? `${path}[${key}]` : `${path}.${key}`;
|
|
78
|
+
if (!Object.prototype.hasOwnProperty.call(descriptor, 'value')) {
|
|
79
|
+
projectionState.complete = false;
|
|
80
|
+
entries.push({ accessor: true, childPath, key, value: debuggerProjectionTruncation('accessor', childPath) });
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
entries.push({ accessor: false, childPath, key, value: descriptor.value });
|
|
84
|
+
}
|
|
85
|
+
return { descriptors, entries, inspectionError: null };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function debuggerProjectionFrame(source, targetPath, projectionState) {
|
|
89
|
+
const inspection = debuggerOwnEntries(source, targetPath, projectionState);
|
|
90
|
+
if (inspection.inspectionError) {
|
|
91
|
+
return { entries: [], sparse: false, target: inspection.inspectionError };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!Array.isArray(source)) {
|
|
95
|
+
return { entries: inspection.entries, sparse: false, target: debuggerJsonRecord() };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const lengthDescriptor = inspection.descriptors.length;
|
|
99
|
+
const length =
|
|
100
|
+
lengthDescriptor && Object.prototype.hasOwnProperty.call(lengthDescriptor, 'value')
|
|
101
|
+
? Number(lengthDescriptor.value)
|
|
102
|
+
: 0;
|
|
103
|
+
let expectedIndex = 0;
|
|
104
|
+
let dense = Number.isSafeInteger(length) && length >= 0;
|
|
105
|
+
for (const key of Object.keys(inspection.descriptors)) {
|
|
106
|
+
const descriptor = inspection.descriptors[key];
|
|
107
|
+
if (!descriptor?.enumerable) continue;
|
|
108
|
+
if (
|
|
109
|
+
!Object.prototype.hasOwnProperty.call(descriptor, 'value') ||
|
|
110
|
+
!isDebuggerArrayIndex(key) ||
|
|
111
|
+
Number(key) !== expectedIndex
|
|
112
|
+
) {
|
|
113
|
+
dense = false;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
expectedIndex += 1;
|
|
117
|
+
}
|
|
118
|
+
if (expectedIndex !== length) dense = false;
|
|
119
|
+
if (dense) return { entries: inspection.entries, sparse: false, target: [] };
|
|
120
|
+
|
|
121
|
+
projectionState.complete = false;
|
|
122
|
+
const target = debuggerJsonRecord();
|
|
123
|
+
setDebuggerJsonProperty(target, '$at', targetPath);
|
|
124
|
+
setDebuggerJsonProperty(target, '$entries', []);
|
|
125
|
+
setDebuggerJsonProperty(target, '$length', Number.isSafeInteger(length) && length >= 0 ? length : '[unavailable]');
|
|
126
|
+
setDebuggerJsonProperty(target, '$truncated', 'sparse-array');
|
|
127
|
+
setDebuggerJsonProperty(target, '$type', 'array');
|
|
128
|
+
return {
|
|
129
|
+
entries: inspection.entries,
|
|
130
|
+
sparse: true,
|
|
131
|
+
target,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function setDebuggerProjectionEntry(frame, entry, value) {
|
|
136
|
+
if (frame.sparse) {
|
|
137
|
+
const projectedEntry = debuggerJsonRecord();
|
|
138
|
+
setDebuggerJsonProperty(
|
|
139
|
+
projectedEntry,
|
|
140
|
+
isDebuggerArrayIndex(entry.key) ? '$index' : '$key',
|
|
141
|
+
isDebuggerArrayIndex(entry.key) ? Number(entry.key) : entry.key,
|
|
142
|
+
);
|
|
143
|
+
setDebuggerJsonProperty(projectedEntry, 'value', value);
|
|
144
|
+
frame.target.$entries.push(projectedEntry);
|
|
145
|
+
} else {
|
|
146
|
+
setDebuggerJsonProperty(frame.target, entry.key, value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function projectDebuggerValue(value, projectionState, path) {
|
|
151
|
+
if (value === null || typeof value !== 'object') {
|
|
152
|
+
if (projectionState.valueCount >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
153
|
+
projectionState.complete = false;
|
|
154
|
+
return debuggerProjectionTruncation('value-limit', path);
|
|
155
|
+
}
|
|
156
|
+
projectionState.valueCount += 1;
|
|
157
|
+
return debuggerPrimitiveProjection(value, projectionState);
|
|
158
|
+
}
|
|
159
|
+
const knownPath = projectionState.seen.get(value);
|
|
160
|
+
if (knownPath !== undefined) {
|
|
161
|
+
if (projectionState.valueCount >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
162
|
+
projectionState.complete = false;
|
|
163
|
+
return debuggerProjectionTruncation('value-limit', path);
|
|
164
|
+
}
|
|
165
|
+
projectionState.valueCount += 1;
|
|
166
|
+
const reference = debuggerJsonRecord();
|
|
167
|
+
setDebuggerJsonProperty(reference, '$ref', knownPath);
|
|
168
|
+
return reference;
|
|
169
|
+
}
|
|
170
|
+
if (projectionState.valueCount >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
171
|
+
projectionState.complete = false;
|
|
172
|
+
return debuggerProjectionTruncation('value-limit', path);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const rootFrame = debuggerProjectionFrame(value, path, projectionState);
|
|
176
|
+
const root = rootFrame.target;
|
|
177
|
+
projectionState.seen.set(value, path);
|
|
178
|
+
projectionState.valueCount += 1;
|
|
179
|
+
const stack = [{ ...rootFrame, depth: 0, index: 0, path }];
|
|
180
|
+
while (stack.length) {
|
|
181
|
+
const frame = stack.at(-1);
|
|
182
|
+
if (frame.index >= frame.entries.length) {
|
|
183
|
+
stack.pop();
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (projectionState.valueCount >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
187
|
+
projectionState.complete = false;
|
|
188
|
+
markDebuggerProjectionTruncated(frame.target, 'value-limit', frame.path);
|
|
189
|
+
stack.pop();
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const entry = frame.entries[frame.index];
|
|
194
|
+
frame.index += 1;
|
|
195
|
+
const childValue = entry.value;
|
|
196
|
+
if (entry.accessor || childValue === null || typeof childValue !== 'object') {
|
|
197
|
+
setDebuggerProjectionEntry(
|
|
198
|
+
frame,
|
|
199
|
+
entry,
|
|
200
|
+
entry.accessor ? childValue : debuggerPrimitiveProjection(childValue, projectionState),
|
|
201
|
+
);
|
|
202
|
+
projectionState.valueCount += 1;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const childKnownPath = projectionState.seen.get(childValue);
|
|
206
|
+
if (childKnownPath !== undefined) {
|
|
207
|
+
const reference = debuggerJsonRecord();
|
|
208
|
+
setDebuggerJsonProperty(reference, '$ref', childKnownPath);
|
|
209
|
+
setDebuggerProjectionEntry(frame, entry, reference);
|
|
210
|
+
projectionState.valueCount += 1;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (frame.depth + 1 >= MAX_DEBUGGER_PROJECTION_DEPTH) {
|
|
214
|
+
projectionState.complete = false;
|
|
215
|
+
setDebuggerProjectionEntry(frame, entry, debuggerProjectionTruncation('depth-limit', entry.childPath));
|
|
216
|
+
projectionState.valueCount += 1;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const childFrame = debuggerProjectionFrame(childValue, entry.childPath, projectionState);
|
|
221
|
+
setDebuggerProjectionEntry(frame, entry, childFrame.target);
|
|
222
|
+
projectionState.seen.set(childValue, entry.childPath);
|
|
223
|
+
projectionState.valueCount += 1;
|
|
224
|
+
stack.push({ ...childFrame, depth: frame.depth + 1, index: 0, path: entry.childPath });
|
|
225
|
+
}
|
|
226
|
+
return root;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function debuggerChildEntries(node) {
|
|
230
|
+
let childrenDescriptor;
|
|
231
|
+
try {
|
|
232
|
+
childrenDescriptor = Object.getOwnPropertyDescriptor(node, 'children');
|
|
233
|
+
} catch {
|
|
234
|
+
return { complete: false, entries: [] };
|
|
235
|
+
}
|
|
236
|
+
if (!childrenDescriptor) return { complete: true, entries: [] };
|
|
237
|
+
if (!Object.prototype.hasOwnProperty.call(childrenDescriptor, 'value')) {
|
|
238
|
+
return { complete: false, entries: [] };
|
|
239
|
+
}
|
|
240
|
+
const children = childrenDescriptor.value;
|
|
241
|
+
if (!Array.isArray(children)) return { complete: true, entries: [] };
|
|
242
|
+
|
|
243
|
+
let descriptors;
|
|
244
|
+
try {
|
|
245
|
+
descriptors = Object.getOwnPropertyDescriptors(children);
|
|
246
|
+
} catch {
|
|
247
|
+
return { complete: false, entries: [] };
|
|
248
|
+
}
|
|
249
|
+
const lengthDescriptor = descriptors.length;
|
|
250
|
+
const length =
|
|
251
|
+
lengthDescriptor && Object.prototype.hasOwnProperty.call(lengthDescriptor, 'value')
|
|
252
|
+
? Number(lengthDescriptor.value)
|
|
253
|
+
: 0;
|
|
254
|
+
const entries = [];
|
|
255
|
+
let complete = true;
|
|
256
|
+
let numericProperties = 0;
|
|
257
|
+
for (const key of Object.keys(descriptors)) {
|
|
258
|
+
if (!isDebuggerArrayIndex(key)) continue;
|
|
259
|
+
numericProperties += 1;
|
|
260
|
+
const descriptor = descriptors[key];
|
|
261
|
+
if (!descriptor?.enumerable || !Object.prototype.hasOwnProperty.call(descriptor, 'value')) {
|
|
262
|
+
complete = false;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (entries.length >= MAX_DEBUGGER_TREE_NODES) {
|
|
266
|
+
complete = false;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
if (descriptor.value) entries.push({ index: Number(key), node: descriptor.value });
|
|
270
|
+
}
|
|
271
|
+
if (!Number.isSafeInteger(length) || length < 0 || numericProperties !== length) complete = false;
|
|
272
|
+
return { complete, entries };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function walkDebuggerTree(node, visitor, ancestors, depth, shouldDescend) {
|
|
276
|
+
if (!node) return true;
|
|
277
|
+
|
|
278
|
+
const path = ancestors.slice();
|
|
279
|
+
const visited = new Set(ancestors);
|
|
280
|
+
if (visited.has(node)) return true;
|
|
281
|
+
const stack = [{ childEntries: null, childIndex: 0, depth, entered: false, node, sourceChildIndex: null }];
|
|
282
|
+
let complete = true;
|
|
283
|
+
let visitedCount = 0;
|
|
284
|
+
while (stack.length) {
|
|
285
|
+
const frame = stack.at(-1);
|
|
286
|
+
if (!frame.entered) {
|
|
287
|
+
if (visited.has(frame.node)) {
|
|
288
|
+
stack.pop();
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (visitedCount >= MAX_DEBUGGER_TREE_NODES) return false;
|
|
292
|
+
visited.add(frame.node);
|
|
293
|
+
visitedCount += 1;
|
|
294
|
+
frame.entered = true;
|
|
295
|
+
if (visitor(frame.node, path, frame.depth, frame.sourceChildIndex) === false) return false;
|
|
296
|
+
path.push(frame.node);
|
|
297
|
+
if (!shouldDescend(frame.node, frame.depth)) {
|
|
298
|
+
frame.childEntries = [];
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const children = debuggerChildEntries(frame.node);
|
|
302
|
+
if (!children.complete) complete = false;
|
|
303
|
+
frame.childEntries = children.entries;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
let childEntry = null;
|
|
308
|
+
while (frame.childIndex < frame.childEntries.length && !childEntry) {
|
|
309
|
+
const candidate = frame.childEntries[frame.childIndex];
|
|
310
|
+
frame.childIndex += 1;
|
|
311
|
+
if (candidate.node && !visited.has(candidate.node)) childEntry = candidate;
|
|
312
|
+
}
|
|
313
|
+
if (childEntry) {
|
|
314
|
+
stack.push({
|
|
315
|
+
childEntries: null,
|
|
316
|
+
childIndex: 0,
|
|
317
|
+
depth: frame.depth + 1,
|
|
318
|
+
entered: false,
|
|
319
|
+
node: childEntry.node,
|
|
320
|
+
sourceChildIndex: childEntry.index,
|
|
321
|
+
});
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
stack.pop();
|
|
325
|
+
path.pop();
|
|
326
|
+
}
|
|
327
|
+
return complete;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const valdiDebuggerTreeModel = Object.freeze({
|
|
331
|
+
attributes(node) {
|
|
332
|
+
return node?.element?.attributes || {};
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
id(node) {
|
|
336
|
+
if (node?.id !== undefined) return String(node.id);
|
|
337
|
+
if (node?.element?.id !== undefined) return String(node.element.id);
|
|
338
|
+
if (node?.key !== undefined) return `${node.tag}:${node.key}`;
|
|
339
|
+
return node?.tag || '';
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
children(node) {
|
|
343
|
+
return node ? debuggerChildEntries(node).entries.map(entry => entry.node) : [];
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
hasChildren(node) {
|
|
347
|
+
return node ? debuggerChildEntries(node).entries.length > 0 : false;
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
walk(node, visitor, ancestors, depth) {
|
|
351
|
+
return walkDebuggerTree(node, visitor, ancestors, depth, () => true);
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
walkVisible(node, visitor, isExpanded, ancestors, depth) {
|
|
355
|
+
return walkDebuggerTree(node, visitor, ancestors, depth, isExpanded);
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
findNode(root, id) {
|
|
359
|
+
if (id === null || id === undefined) return null;
|
|
360
|
+
let found = null;
|
|
361
|
+
valdiDebuggerTreeModel.walk(
|
|
362
|
+
root,
|
|
363
|
+
node => {
|
|
364
|
+
if (valdiDebuggerTreeModel.id(node) !== String(id)) return true;
|
|
365
|
+
found = node;
|
|
366
|
+
return false;
|
|
367
|
+
},
|
|
368
|
+
[],
|
|
369
|
+
0,
|
|
370
|
+
);
|
|
371
|
+
return found;
|
|
372
|
+
},
|
|
373
|
+
|
|
374
|
+
pathToNode(root, id) {
|
|
375
|
+
if (id === null || id === undefined) return [];
|
|
376
|
+
let path = [];
|
|
377
|
+
valdiDebuggerTreeModel.walk(
|
|
378
|
+
root,
|
|
379
|
+
(node, ancestors) => {
|
|
380
|
+
if (valdiDebuggerTreeModel.id(node) !== String(id)) return true;
|
|
381
|
+
path = [...ancestors, node];
|
|
382
|
+
return false;
|
|
383
|
+
},
|
|
384
|
+
[],
|
|
385
|
+
0,
|
|
386
|
+
);
|
|
387
|
+
return path;
|
|
388
|
+
},
|
|
389
|
+
|
|
390
|
+
projectValue(value) {
|
|
391
|
+
const projectionState = {
|
|
392
|
+
complete: true,
|
|
393
|
+
seen: new Map(),
|
|
394
|
+
valueCount: 0,
|
|
395
|
+
};
|
|
396
|
+
const projected = projectDebuggerValue(value, projectionState, '$');
|
|
397
|
+
return {
|
|
398
|
+
complete: projectionState.complete,
|
|
399
|
+
value: projected,
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
stringifyValue(value, spacing) {
|
|
404
|
+
const projection = valdiDebuggerTreeModel.projectValue(value);
|
|
405
|
+
return JSON.stringify(projection.value, null, spacing);
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
formatValue(value, spacing) {
|
|
409
|
+
const projection = valdiDebuggerTreeModel.projectValue(value);
|
|
410
|
+
return typeof projection.value === 'string' ? projection.value : JSON.stringify(projection.value, null, spacing);
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
projectTree(root) {
|
|
414
|
+
if (!root) {
|
|
415
|
+
return {
|
|
416
|
+
complete: true,
|
|
417
|
+
format: 'valdi-debugger-tree-v1',
|
|
418
|
+
nodeCount: 0,
|
|
419
|
+
nodes: [],
|
|
420
|
+
rootIndex: null,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const nodes = [];
|
|
425
|
+
const nodeIndexes = new Map();
|
|
426
|
+
const projectionState = {
|
|
427
|
+
complete: true,
|
|
428
|
+
seen: new Map(),
|
|
429
|
+
valueCount: 0,
|
|
430
|
+
};
|
|
431
|
+
const traversalComplete = valdiDebuggerTreeModel.walk(
|
|
432
|
+
root,
|
|
433
|
+
(node, ancestors, depth, sourceChildIndex) => {
|
|
434
|
+
const index = nodes.length;
|
|
435
|
+
const parent = ancestors.at(-1);
|
|
436
|
+
const parentIndex = parent ? nodeIndexes.get(parent) : null;
|
|
437
|
+
nodeIndexes.set(node, index);
|
|
438
|
+
projectionState.seen.set(node, `$.nodes[${index}].data`);
|
|
439
|
+
const data = debuggerJsonRecord();
|
|
440
|
+
const inspection = debuggerOwnEntries(node, `$.nodes[${index}].data`, projectionState);
|
|
441
|
+
if (inspection.inspectionError) {
|
|
442
|
+
markDebuggerProjectionTruncated(data, 'unavailable-properties', `$.nodes[${index}].data`);
|
|
443
|
+
}
|
|
444
|
+
for (const entry of inspection.entries) {
|
|
445
|
+
if (entry.key === 'children') continue;
|
|
446
|
+
if (projectionState.valueCount >= MAX_DEBUGGER_PROJECTION_VALUES) {
|
|
447
|
+
projectionState.complete = false;
|
|
448
|
+
markDebuggerProjectionTruncated(data, 'value-limit', `$.nodes[${index}].data`);
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
setDebuggerJsonProperty(
|
|
452
|
+
data,
|
|
453
|
+
entry.key,
|
|
454
|
+
entry.accessor ? entry.value : projectDebuggerValue(entry.value, projectionState, entry.childPath),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
nodes.push({
|
|
458
|
+
childIndexes: [],
|
|
459
|
+
data,
|
|
460
|
+
depth,
|
|
461
|
+
index,
|
|
462
|
+
parentIndex: parentIndex === undefined ? null : parentIndex,
|
|
463
|
+
sourceChildIndex,
|
|
464
|
+
});
|
|
465
|
+
if (parentIndex !== null && parentIndex !== undefined) {
|
|
466
|
+
nodes[parentIndex].childIndexes.push(index);
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
[],
|
|
470
|
+
0,
|
|
471
|
+
);
|
|
472
|
+
return {
|
|
473
|
+
complete: traversalComplete && projectionState.complete,
|
|
474
|
+
format: 'valdi-debugger-tree-v1',
|
|
475
|
+
nodeCount: nodes.length,
|
|
476
|
+
nodes,
|
|
477
|
+
rootIndex: 0,
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
projectSnapshot(snapshot) {
|
|
482
|
+
let metadata = debuggerJsonRecord();
|
|
483
|
+
try {
|
|
484
|
+
const descriptors = Object.getOwnPropertyDescriptors(snapshot && typeof snapshot === 'object' ? snapshot : {});
|
|
485
|
+
for (const key of Object.keys(descriptors)) {
|
|
486
|
+
if (key !== 'tree') Object.defineProperty(metadata, key, descriptors[key]);
|
|
487
|
+
}
|
|
488
|
+
} catch {
|
|
489
|
+
metadata = debuggerProjectionTruncation('unavailable-properties', '$');
|
|
490
|
+
}
|
|
491
|
+
const projectedMetadata = valdiDebuggerTreeModel.projectValue(metadata);
|
|
492
|
+
const projectedTree = valdiDebuggerTreeModel.projectTree(snapshot?.tree);
|
|
493
|
+
const projection = debuggerJsonRecord();
|
|
494
|
+
for (const key of Object.keys(projectedMetadata.value)) {
|
|
495
|
+
setDebuggerJsonProperty(projection, key, projectedMetadata.value[key]);
|
|
496
|
+
}
|
|
497
|
+
setDebuggerJsonProperty(projection, 'projectionComplete', projectedMetadata.complete && projectedTree.complete);
|
|
498
|
+
setDebuggerJsonProperty(projection, 'tree', projectedTree);
|
|
499
|
+
return projection;
|
|
500
|
+
},
|
|
501
|
+
|
|
502
|
+
restoreTree(value) {
|
|
503
|
+
if (
|
|
504
|
+
!value ||
|
|
505
|
+
value.format !== 'valdi-debugger-tree-v1' ||
|
|
506
|
+
!Array.isArray(value.nodes) ||
|
|
507
|
+
!Number.isInteger(value.rootIndex)
|
|
508
|
+
) {
|
|
509
|
+
return value;
|
|
510
|
+
}
|
|
511
|
+
const nodes = value.nodes.map(record => {
|
|
512
|
+
const node = debuggerJsonRecord();
|
|
513
|
+
let descriptors;
|
|
514
|
+
try {
|
|
515
|
+
descriptors = Object.getOwnPropertyDescriptors(record?.data || debuggerJsonRecord());
|
|
516
|
+
} catch {
|
|
517
|
+
descriptors = debuggerJsonRecord();
|
|
518
|
+
}
|
|
519
|
+
for (const key of Object.keys(descriptors)) {
|
|
520
|
+
const descriptor = descriptors[key];
|
|
521
|
+
if (descriptor?.enumerable && Object.prototype.hasOwnProperty.call(descriptor, 'value')) {
|
|
522
|
+
setDebuggerJsonProperty(node, key, descriptor.value);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return node;
|
|
526
|
+
});
|
|
527
|
+
for (let index = 0; index < value.nodes.length; index += 1) {
|
|
528
|
+
const childIndexes = Array.isArray(value.nodes[index]?.childIndexes) ? value.nodes[index].childIndexes : [];
|
|
529
|
+
setDebuggerJsonProperty(
|
|
530
|
+
nodes[index],
|
|
531
|
+
'children',
|
|
532
|
+
childIndexes
|
|
533
|
+
.filter(childIndex => Number.isInteger(childIndex) && childIndex >= 0 && childIndex < nodes.length)
|
|
534
|
+
.map(childIndex => nodes[childIndex]),
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
return nodes[value.rootIndex] || null;
|
|
538
|
+
},
|
|
539
|
+
});
|