Primitive Types

Describes how to deal with primitive field types from Cosmos to Domain

Primitive type fields are a one-to-one copy from Cosmos DB model into the Domain props.

Cosmos DB Model

/infrastructure/data-sources/cosmos-db/models/physician.ts
lastName: string;

Domain Props

/domain/contexts/physician/physician.ts
lastName: string;
Domain Props on left, Cosmos DB Model on right
  • Don't need id field on Domain Props side because already defined in EntityProps

  • Every field in domain props is required regardless of if it's optional on cosmos db side

Domain Entity Reference

export interface PhysicianEntityReference extends Readonly<PhysicianProps> {} 
  • primitive types are copied automatically as read-only in entity reference

  • no need to omit primitive type fields from entity reference like you would for non-primitive type

  • if domain object only has primitive types, entity reference should look exactly as above

Domain Class

  • Primitive fields require getter and setter methods in the domain class of the object

Getter

/domain/contexts/physician/physician.ts
get lastName() {
    return this.props.lastName;
}

Setter

/domain/contexts/physician/physician.ts
public requestSetLastName(lastName: string) {
    this.props.lastName = lastName;
}

Domain Adapter

  • Primitive fields require getter and setter methods in the domain adapter of the object

Getter

/domain/infrastructure/persistence/physician.domain-adapter.ts
get lastName() {
    return this.doc.lastName;
}

Setter

/domain/infrastructure/persistence/physician.domain-adapter.ts
set lastName(lastName) {
    this.doc.lastName = lastName;
}

Last updated

Was this helpful?