| 562 | } |
| 563 | |
| 564 | function removeUndefinedFields(obj: any): any { |
| 565 | if (obj === null) { |
| 566 | return undefined; |
| 567 | } |
| 568 | |
| 569 | if (Array.isArray(obj)) { |
| 570 | return obj.map(removeUndefinedFields); |
| 571 | } |
| 572 | |
| 573 | if (typeof obj === "object") { |
| 574 | const copy: any = {}; |
| 575 | for (const [key, value] of Object.entries(obj)) { |
| 576 | if (obj[key] !== undefined) { |
| 577 | copy[key] = removeUndefinedFields(value); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | if (Object.keys(copy).length === 0) { |
| 582 | return []; |
| 583 | } |
| 584 | |
| 585 | return copy; |
| 586 | } |
| 587 | |
| 588 | return obj; |
| 589 | } |
| 590 | |
| 591 | return removeUndefinedFields(result); |
| 592 | } |