domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
37 lines (36 loc) • 1.74 kB
TypeScript
import { DomainObject } from './DomainObject';
import { MARK_AS_DOMAIN_LITERAL } from './markers';
export { MARK_AS_DOMAIN_LITERAL } from './markers';
/**
* In Domain Driven Design, a Literal (a.k.a. Value Object), is a type of Domain Object for which:
* - properties are immutable
* - i.e., it represents some literal value which happens to have a structured object shape
* - i.e., if you change the value of any of its properties, it is a different literal
* - identity does not matter
* - i.e., it is uniquely identifiable by its non-metadata properties
*
* The purpose of a Domain Literal is to represent distinct, literal values which happen to have a structured object shape
*
* For example,
* - A `Address { street, city, state, country }` is a literal. Changing any of the properties, like `street`, produces a completely new address
* - A `Geocode { latitude, longitude }` is a literal. Changing either property means you are dealing with a new geocode
*/
export declare class DomainLiteral<T extends Record<string, any>> extends DomainObject<T> {
/**
* DomainLiteral marker symbol for cross-version compatibility.
*
* Uses Symbol.for() to create a global symbol that works across different versions
* of the domain-objects library. The value is the version string.
*/
static readonly [MARK_AS_DOMAIN_LITERAL]: string;
/**
* `DomainLiteral.primary` defines the surrogate key of the domain.literal, utilized as the primary key in persistance
*
* for example,
* - an `Address { uuid, ... }` is likely going to have a primary key of `uuid`
*
* ref
* - https://en.wikipedia.org/wiki/Surrogate_key
*/
static primary?: readonly [string];
}