{"version":3,"sources":["../src/domain.ts"],"sourcesContent":["import utils from '@eventcatalog/sdk';\nimport chalk from 'chalk';\nimport type { CompassConfig } from './compass';\nimport type { DomainOption, DomainSpec } from './types';\n\nfunction isDomainSpec(option: DomainOption): option is DomainSpec {\n  return 'id' in option && 'name' in option && 'version' in option;\n}\n\nexport function resolveDomain(config: CompassConfig, option: DomainOption): DomainSpec | null {\n  if (isDomainSpec(option)) {\n    return option;\n  }\n\n  if (option.from === 'label') {\n    if (config.labels) {\n      for (const label of config.labels) {\n        if (Object.prototype.hasOwnProperty.call(option.mapping, label)) {\n          return option.mapping[label];\n        }\n      }\n    }\n  } else if (option.from === 'customField' && option.key) {\n    const field = config.customFields?.find((f) => f.name === option.key);\n    if (field && typeof field.value === 'string' && Object.prototype.hasOwnProperty.call(option.mapping, field.value)) {\n      return option.mapping[field.value];\n    }\n  }\n\n  if (option.fallback && option.fallback !== 'skip') {\n    return option.fallback;\n  }\n  return null;\n}\n\nexport default class Domain {\n  id: string;\n  name: string;\n  version: string;\n  private sdk: ReturnType<typeof utils>;\n\n  constructor(id: string, name: string, version: string, projectDir: string) {\n    this.id = id;\n    this.name = name;\n    this.version = version;\n    this.sdk = utils(projectDir);\n  }\n\n  async processDomain() {\n    const { getDomain, writeDomain, versionDomain } = this.sdk;\n\n    // Try and get the domain\n    const domain = await getDomain(this.id, this.version || 'latest');\n    const currentDomain = await getDomain(this.id, 'latest');\n\n    console.log(chalk.blue(`\\nProcessing domain: ${this.name} (v${this.version})`));\n\n    // Found a domain, but the versions do not match\n    if (currentDomain && currentDomain.version !== this.version) {\n      await versionDomain(this.id);\n      console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n    }\n\n    // Do we need to create a new domain?\n    if (!domain || (domain && domain.version !== this.version)) {\n      await writeDomain({\n        id: this.id,\n        name: this.name,\n        version: this.version,\n        markdown: `## Architecture diagram\n  <NodeGraph />`,\n      });\n      console.log(chalk.cyan(` - Domain (v${this.version}) created`));\n    }\n\n    if (currentDomain && currentDomain.version === this.version) {\n      console.log(chalk.yellow(` - Domain (v${this.version}) already exists, skipped creation...`));\n    }\n  }\n\n  async addServiceToDomain(serviceId: string, serviceVersion: string = '0.0.0') {\n    const { addServiceToDomain } = this.sdk;\n\n    await addServiceToDomain(\n      this.id,\n      {\n        id: serviceId,\n        version: serviceVersion,\n      },\n      this.version\n    );\n    console.log(chalk.cyan(` - Service ID ${serviceId} version ${serviceVersion} added to domain ${this.id}!`));\n  }\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,OAAO,WAAW;AAIlB,SAAS,aAAa,QAA4C;AAChE,SAAO,QAAQ,UAAU,UAAU,UAAU,aAAa;AAC5D;AAEO,SAAS,cAAc,QAAuB,QAAyC;AAC5F,MAAI,aAAa,MAAM,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,SAAS;AAC3B,QAAI,OAAO,QAAQ;AACjB,iBAAW,SAAS,OAAO,QAAQ;AACjC,YAAI,OAAO,UAAU,eAAe,KAAK,OAAO,SAAS,KAAK,GAAG;AAC/D,iBAAO,OAAO,QAAQ,KAAK;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAAA,EACF,WAAW,OAAO,SAAS,iBAAiB,OAAO,KAAK;AACtD,UAAM,QAAQ,OAAO,cAAc,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,GAAG;AACpE,QAAI,SAAS,OAAO,MAAM,UAAU,YAAY,OAAO,UAAU,eAAe,KAAK,OAAO,SAAS,MAAM,KAAK,GAAG;AACjH,aAAO,OAAO,QAAQ,MAAM,KAAK;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,OAAO,YAAY,OAAO,aAAa,QAAQ;AACjD,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;AAEA,IAAqB,SAArB,MAA4B;AAAA,EAM1B,YAAY,IAAY,MAAc,SAAiB,YAAoB;AACzE,SAAK,KAAK;AACV,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAA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