(
sourceSchema: Record<string, unknown>,
canonicalSchema: Record<string, unknown>
)
| 1241 | } |
| 1242 | |
| 1243 | export function findSharedSchemaDefinitions( |
| 1244 | sourceSchema: Record<string, unknown>, |
| 1245 | canonicalSchema: Record<string, unknown> |
| 1246 | ): Set<string> { |
| 1247 | const sourceDefinitions = collectDefinitions(sourceSchema); |
| 1248 | const canonicalDefinitions = collectDefinitions(canonicalSchema); |
| 1249 | const shared = new Set<string>(); |
| 1250 | |
| 1251 | for (const [name, sourceDefinition] of Object.entries(sourceDefinitions)) { |
| 1252 | const canonicalDefinition = canonicalDefinitions[name]; |
| 1253 | if ( |
| 1254 | canonicalDefinition !== undefined && |
| 1255 | stableStringify(normalizeDefinitionForComparison(sourceDefinition)) === |
| 1256 | stableStringify(normalizeDefinitionForComparison(canonicalDefinition)) |
| 1257 | ) { |
| 1258 | shared.add(name); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | let changed = true; |
| 1263 | while (changed) { |
| 1264 | changed = false; |
| 1265 | for (const name of [...shared]) { |
| 1266 | const refs = new Set([ |
| 1267 | ...collectLocalDefinitionRefNames(sourceDefinitions[name]), |
| 1268 | ...collectLocalDefinitionRefNames(canonicalDefinitions[name]), |
| 1269 | ]); |
| 1270 | for (const refName of refs) { |
| 1271 | if (refName !== name && !shared.has(refName)) { |
| 1272 | shared.delete(name); |
| 1273 | changed = true; |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | return shared; |
| 1281 | } |
| 1282 | |
| 1283 | export function collectReachableDefinitionNames( |
| 1284 | schema: Record<string, unknown>, |
no test coverage detected
searching dependent graphs…