(opts: {
fromLabel: string;
toLabel: string;
fromTable: TableExtract;
toTable: TableExtract;
})
| 165 | } |
| 166 | |
| 167 | export function printFavoritePairDiff(opts: { |
| 168 | fromLabel: string; |
| 169 | toLabel: string; |
| 170 | fromTable: TableExtract; |
| 171 | toTable: TableExtract; |
| 172 | }) { |
| 173 | const diff = diffKeyedRecords( |
| 174 | opts.fromTable.recordsByKey, |
| 175 | opts.toTable.recordsByKey |
| 176 | ); |
| 177 | |
| 178 | console.log(`\n=== ${opts.fromLabel} -> ${opts.toLabel} ===`); |
| 179 | console.log( |
| 180 | `Rows: ${opts.fromTable.recordsByKey.size} -> ${opts.toTable.recordsByKey.size} (+${diff.added.length} / -${diff.removed.length} / ~${diff.changed.length})` |
| 181 | ); |
| 182 | |
| 183 | if (opts.fromTable.duplicateKeys.length) { |
| 184 | console.log( |
| 185 | `! Warning: duplicate keys in FROM: ${Array.from(new Set(opts.fromTable.duplicateKeys)).sort().join(', ')}` |
| 186 | ); |
| 187 | } |
| 188 | if (opts.toTable.duplicateKeys.length) { |
| 189 | console.log( |
| 190 | `! Warning: duplicate keys in TO: ${Array.from(new Set(opts.toTable.duplicateKeys)).sort().join(', ')}` |
| 191 | ); |
| 192 | } |
| 193 | |
| 194 | if (diff.added.length) { |
| 195 | console.log(`\n+ Added (${diff.added.length})`); |
| 196 | for (const { id, record } of diff.added) { |
| 197 | console.log( |
| 198 | ` + ${favoriteLabel(id)} (index=${formatValue('index', record.index ?? null)})` |
| 199 | ); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (diff.removed.length) { |
| 204 | console.log(`\n- Removed (${diff.removed.length})`); |
| 205 | for (const { id, record } of diff.removed) { |
| 206 | console.log( |
| 207 | ` - ${favoriteLabel(id)} (index=${formatValue('index', record.index ?? null)})` |
| 208 | ); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if (diff.changed.length) { |
| 213 | console.log(`\n~ Changed (${diff.changed.length})`); |
| 214 | for (const change of diff.changed) { |
| 215 | console.log(` ~ ${favoriteLabel(change.id)}`); |
| 216 | for (const field of change.fields) { |
| 217 | console.log( |
| 218 | ` - ${field.key}: ${formatValue(field.key, field.from)} -> ${formatValue(field.key, field.to)}` |
| 219 | ); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (!diff.added.length && !diff.removed.length && !diff.changed.length) { |
no test coverage detected