seagull-js/seagull

View on GitHub
packages/deploy-aws/src/lib/find_alias_config.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { SchemaArn } from '../types'

export function findAliasConfig(arns: SchemaArn[], domains: string[]) {
  return arns.find(schemaArn => !!findSchemaArn(schemaArn, domains))
}

function findSchemaArn({ names }: SchemaArn, domains: string[]) {
  return domains.find(domain => findNoMatchDomain(domain, names)) === undefined
}

function findNoMatchDomain(domain: string, schemata: string[]) {
  return schemata.find(schema => domainMatch(domain, schema)) === undefined
}

function domainMatch(domain: string, schema: string) {
  const regExp = `^${schema.replace(/\./g, '\\.').replace(/\*/g, '[^ ]*')}\\b`
  return schema === domain || domain.match(regExp) !== null
}