-
Notifications
You must be signed in to change notification settings - Fork 15
fix: human output no longer displaying undefined #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4e8c94f
f0de9f7
af35ade
a1fa148
b7fbcb9
1549b6f
721824a
810e2d7
18af6b9
f5bd404
c2dbc57
812ca74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,15 @@ export class HumanReporter extends QueryReporter { | |
| (field: string) => | ||
| (formattedColumns[field] = { | ||
| header: field.toUpperCase(), | ||
| get: (row): string => get(row, field) as string, | ||
| get: (row): string => { | ||
| // first test if key exists, if so, return value | ||
| if (Reflect.has(row, field)) { | ||
| return (Reflect.get(row, field) as string) || ''; | ||
| } else { | ||
| // if not, try to find it query | ||
| return (get(row, field) as string) || ''; | ||
| } | ||
| }, | ||
| }) | ||
| ); | ||
| return formattedColumns; | ||
|
|
@@ -136,7 +144,7 @@ export class HumanReporter extends QueryReporter { | |
| // some fields will return a JSON object that isn't accessible via the query (SELECT Metadata FROM RemoteProxy) | ||
| // some will return a JSON that IS accessible via the query (SELECT owner.Profile.Name FROM Lead) | ||
| // querying (SELECT Metadata.isActive FROM RemoteProxy) throws a SOQL validation error, so we have to display the entire Metadata object | ||
| queryResults.map((qr) => { | ||
| queryResults.forEach((qr) => { | ||
| const result = qr as Record<string, unknown>; | ||
| this.data.columns.forEach((col) => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
|
|
@@ -167,6 +175,7 @@ export class HumanReporter extends QueryReporter { | |
| } | ||
| } | ||
|
|
||
| const subResults: Array<Record<string, unknown>> = []; | ||
| if (children.length > 0) { | ||
| const childrenRows: Record<string, unknown> = {}; | ||
| children.forEach((child) => { | ||
|
|
@@ -180,19 +189,28 @@ export class HumanReporter extends QueryReporter { | |
| if (childO) { | ||
| const childRecords = getArray(childO, 'records', []); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| childRecords.forEach((record: unknown) => { | ||
| childRecords.forEach((record: unknown, index) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be more than one child record from a subquery, Account record can have more than one contact associated to it. For subquery records 2-n a synthetic record needs to be added to the results to produce output like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a NUT to cover this case? |
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const newResult: Record<string, unknown> = {}; | ||
| Object.entries(record as never).forEach(([key, value]) => { | ||
| // merge subqueries with the "parent" so they are on the same row | ||
| Reflect.defineProperty(result as Record<string, unknown>, `${child.toString()}.${key}`, { | ||
| value: value ? value : chalk.bold('null'), | ||
| }); | ||
| if (!index) { | ||
| Reflect.defineProperty(result as Record<string, unknown>, `${child.toString()}.${key}`, { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add subquery data to first query record |
||
| value: value ? value : chalk.bold('null'), | ||
| }); | ||
| } else { | ||
| Reflect.defineProperty(newResult, `${child.toString()}.${key}`, { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add subquery data to subquery records 2-n |
||
| value: value ? value : chalk.bold('null'), | ||
| }); | ||
| } | ||
| }); | ||
| if (index) { | ||
| subResults.push(newResult); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| newResults.push(result); | ||
| newResults.push(result, ...subResults); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Push parent and additional subquery records into result. |
||
| return newResults; | ||
| }, [] as unknown[]); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the get to first check if the field, as given, can be referenced directly, This solves case where property has a name like
foo.bar. If cannot be directly referenced then delegate toget