Skip to content

Commit

Permalink
feat: nested objects (#13444)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicohrubec authored Aug 21, 2024
1 parent c8bfae1 commit a8def42
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions packages/node/src/debugger-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ function unrollArray(objectId: string | undefined): Promise<unknown[]> {
objectId,
ownProperties: true,
},
(err, params) => {
const arrayProps = params.result
.filter(v => v.name !== 'length' && !isNaN(parseInt(v.name, 10)))
.sort((a, b) => parseInt(a.name, 10) - parseInt(b.name, 10))
.map(v => v?.value?.value);
async (err, params) => {
const arrayProps = await Promise.all(
params.result
.filter(v => v.name !== 'length' && !isNaN(parseInt(v.name, 10)))
.sort((a, b) => parseInt(a.name, 10) - parseInt(b.name, 10))
.map(async v => {
if (v.value?.type === 'object') {
if (v.value?.subtype === 'array') {
return unrollArray(v?.value?.objectId);
} else {
return unrollObject(v?.value?.objectId);
}
} else {
return v?.value?.value;
}
})
);

resolve(arrayProps);
},
Expand All @@ -47,16 +59,22 @@ function unrollObject(objectId: string | undefined): Promise<Record<string, unkn
objectId,
ownProperties: true,
},
(err, params) => {
const obj = params.result
.map<[string, unknown]>(v => [v.name, v?.value?.value])
.reduce(
(acc, [key, val]) => {
acc[key] = val;
return acc;
},
{} as Record<string, unknown>,
);
async (err, params) => {
const obj = await params.result.reduce(async (accPromise, v) => {
const acc = await accPromise;

if (v.value?.type === 'object') {
if (v.value.subtype === 'array') {
acc[v.name] = await unrollArray(v.value.objectId);
} else {
acc[v.name] = await unrollObject(v.value.objectId);
}
} else {
acc[v.name] = v?.value?.value;
}

return acc;
}, Promise.resolve({} as Record<string, unknown>));

resolve(obj);
},
Expand Down

0 comments on commit a8def42

Please sign in to comment.