(opts: {
fromLabel: string;
toLabel: string;
fromMeta: RootDocMetaExtract;
toMeta: RootDocMetaExtract;
})
| 73 | } |
| 74 | |
| 75 | export function printRootDocPairDiff(opts: { |
| 76 | fromLabel: string; |
| 77 | toLabel: string; |
| 78 | fromMeta: RootDocMetaExtract; |
| 79 | toMeta: RootDocMetaExtract; |
| 80 | }) { |
| 81 | const diff = diffKeyedRecords( |
| 82 | opts.fromMeta.recordsById, |
| 83 | opts.toMeta.recordsById |
| 84 | ); |
| 85 | |
| 86 | console.log(`\n=== ${opts.fromLabel} -> ${opts.toLabel} ===`); |
| 87 | console.log( |
| 88 | `Docs: ${opts.fromMeta.recordsById.size} -> ${opts.toMeta.recordsById.size} (+${diff.added.length} / -${diff.removed.length} / ~${diff.changed.length})` |
| 89 | ); |
| 90 | |
| 91 | if (opts.fromMeta.duplicateIds.length) { |
| 92 | console.log( |
| 93 | `! Warning: duplicate page ids in FROM: ${Array.from(new Set(opts.fromMeta.duplicateIds)).sort().join(', ')}` |
| 94 | ); |
| 95 | } |
| 96 | if (opts.toMeta.duplicateIds.length) { |
| 97 | console.log( |
| 98 | `! Warning: duplicate page ids in TO: ${Array.from(new Set(opts.toMeta.duplicateIds)).sort().join(', ')}` |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | if (diff.added.length) { |
| 103 | console.log(`\n+ Added (${diff.added.length})`); |
| 104 | for (const { id, record } of diff.added) { |
| 105 | console.log(` + ${docLabel(id, record)}`); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (diff.removed.length) { |
| 110 | console.log(`\n- Removed (${diff.removed.length})`); |
| 111 | for (const { id, record } of diff.removed) { |
| 112 | console.log(` - ${docLabel(id, record)}`); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (diff.changed.length) { |
| 117 | console.log(`\n~ Changed (${diff.changed.length})`); |
| 118 | for (const change of diff.changed) { |
| 119 | const fromTitle = change.fromRecord.title; |
| 120 | const toTitle = change.toRecord.title; |
| 121 | |
| 122 | let header = ` ~ ${change.id}`; |
| 123 | if ( |
| 124 | typeof fromTitle === 'string' && |
| 125 | typeof toTitle === 'string' && |
| 126 | fromTitle !== toTitle |
| 127 | ) { |
| 128 | header += ` "${fromTitle}" -> "${toTitle}"`; |
| 129 | } else if (typeof toTitle === 'string' && toTitle.trim()) { |
| 130 | header += ` "${toTitle}"`; |
| 131 | } |
| 132 | console.log(header); |
no test coverage detected