( obj: SubqlRuntimeHandler | SubqlRuntimeHandler[] | string, indent = 2, currentIndent = 0 )
| 479 | } |
| 480 | |
| 481 | export function tsStringify( |
| 482 | obj: SubqlRuntimeHandler | SubqlRuntimeHandler[] | string, |
| 483 | indent = 2, |
| 484 | currentIndent = 0 |
| 485 | ): string { |
| 486 | if (typeof obj !== 'object' || obj === null) { |
| 487 | if (typeof obj === 'string' && obj.includes('EthereumHandlerKind')) { |
| 488 | return obj; // Return the string as-is without quotes |
| 489 | } |
| 490 | return JSON.stringify(obj); |
| 491 | } |
| 492 | |
| 493 | if (Array.isArray(obj)) { |
| 494 | const items = obj.map((item) => tsStringify(item, indent, currentIndent + indent)); |
| 495 | return `[\n${items.map((item) => ' '.repeat(currentIndent + indent) + item).join(',\n')}\n${' '.repeat( |
| 496 | currentIndent |
| 497 | )}]`; |
| 498 | } |
| 499 | |
| 500 | const entries = Object.entries(obj); |
| 501 | const result = entries.map(([key, value]) => { |
| 502 | const valueStr = tsStringify(value, indent, currentIndent + indent); |
| 503 | return `${' '.repeat(currentIndent + indent)}${key}: ${valueStr}`; |
| 504 | }); |
| 505 | |
| 506 | return `{\n${result.join(',\n')}\n${' '.repeat(currentIndent)}}`; |
| 507 | } |
no test coverage detected