Skip to content
7 changes: 7 additions & 0 deletions v2/workflows/workflows/__tests__/registry.unique.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getRegistry } from '../test-utils';

const registry = getRegistry();

it('registry', () => {
registry.validateUnique()
});
18 changes: 18 additions & 0 deletions v2/workflows/workflows/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ export class Registry {
});
}

public validateUnique() {
const seen = new Set<string>(); // set to store unique chain_names
const duplicates = new Set<string>(); // set to store duplicate chain_names

this.chains.forEach(chain => {
let chainName = chain.chain_name
if (seen.has(chainName)) {
duplicates.add(chainName)
} else {
seen.add(chainName)
}
})
const duplicatesArr = Array.from(duplicates)
if (duplicatesArr.length > 0) {
throw new Error(`duplicates found: ${duplicatesArr.join(', ')}`)
}
}

public get count() {
return {
chains: this.chains.length,
Expand Down
Loading