public constructor()

in src/codeartifact/repository.ts [120:185]


  public constructor(scope: Construct, id: string, props?: RepositoryProps) {
    super(scope, id);

    if (props?.domainExists && !props.domainName) {
      throw new Error('domainExists cannot be specified if no domainName is provided');
    }
    if (props?.upstreams && !props.domainExists) {
      throw new Error('upstreams can only be specified if domainExists and domainName are provided');
    }

    const domainName = props?.domainName ?? this.node.addr;
    const domain = props?.domainExists ? undefined : new CfnDomain(this, 'Domain', { domainName });
    const repositoryName = props?.repositoryName ?? this.node.addr;

    /**
     * This repository does not have any upstreams or external connections, so
     * it should be exempt from surprises. Concretely, any apckages published
     * to this repository will go in there, so we can separate "hand-published"
     * from "from upstream or external" packages.
     */
    const publishingUpstream = domain && new CfnRepository(this, 'Publishing', {
      description: 'Publishing repository',
      domainName: domain.attrName,
      repositoryName: `${repositoryName}-publish-overlay`,
    });

    const repository = new CfnRepository(this, 'Default', {
      description: props?.description,
      domainName: domain?.attrName ?? domainName,
      externalConnections: Lazy.list({
        produce: () =>
          !domain && this.#externalConnections.length > 0
            ? this.#externalConnections
            : undefined,
      }),
      repositoryName,
      // NOTE: Upstream order IS important, as CodeArtifact repositories query
      // their upstreams in the order they are listed in. The publishing
      // upstream is hence last in the list, so we get packages from the
      // "official" sources first.
      upstreams: Lazy.list({
        produce: () =>
          domain && this.#externalConnections.length > 0
            ? [
              ...(props?.upstreams ?? []),
              ...this.#externalConnections.map((name) => this.makeUpstreamForId(name, { domain, repositoryName })),
              ...(publishingUpstream ? [publishingUpstream.attrName] : []),
            ]
            : publishingUpstream ? [publishingUpstream?.attrName] : props?.upstreams,
      }),
    });

    this.repositoryDomainArn = domain?.attrArn ?? Stack.of(this).formatArn({
      service: 'codeartifact',
      resource: 'domain',
      arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
      resourceName: domainName,
    });
    this.repositoryDomainName = repository.attrDomainName;
    this.repositoryDomainOwner = repository.attrDomainOwner;
    this.repositoryArn = repository.attrArn;
    this.repositoryName = repository.attrName;

    this.publishingRepositoryArn = publishingUpstream?.attrArn ?? this.repositoryArn;
    this.publishingRepositoryName = publishingUpstream?.attrName ?? repositoryName;
  }