Types.DocumentArray

Describes how to deal with a cosmos db field type of Types.DocumentArray

Cosmos DB Model

/infrastructure/data-sources/cosmos-db/models/physician.ts
licenses: Types.DocumentArray<PhysicianLicense>;

Domain Props

/domain/contexts/physician/physician.ts
readonly licenses: PropArray<PhysicianLicenseProps>;

Domain Entity Reference

/domain/contexts/physician/physician.ts
export interface PhysicianEntityReference
    extends Readonly<
        Omit<
            PhysicianProps,
            "licenses"
        >
    > {
    readonly licenses: ReadonlyArray<PhysicianLicenseEntityReference>;
}

Domain Class

Getter

/domain/contexts/physician/physician.ts
get licenses(): ReadonlyArray<PhysicianLicenseEntityReference> {
    return this.props.licenses.items.map(
        (license) => new PhysicianLicense(license, this.context)
    );
}

Setter

  • No setter for domain objects local to the aggregate root (Entity or ValueObject)

  • Only need setRef method for PopulatedDoc type fields

Domain Adapter

Getter

/domain/infrastructure/persistence/physician.domain-adapter.ts
get licenses() {
    if (this.doc.licenses) {
        return new MongoosePropArray(this.doc.licenses, PhysicianLicenseDomainAdapter);
    }
}
  • Note: PhysicianLicenseDomainAdapter should exist in same file as PhysicianDomainAdapter

Setter

  • No setter for Types.DocumentArray type fields

  • Wil be handled in domain adapter for that domain context, PhysicianLicenseDomainAdapter

Last updated