Skip to content

JavierMF/domain-primitives

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeFactor

domain-primitives

A domain primitives library in Kotlin inspired by the concepts introduced in Secury By Design book.

A value object so precise in its definition that it, by its mere existence, manifests its validity is called a domain primitive.

In summary, a domain primitive is a value object with some invariants enforced at the time of creation. Using domain primitives instead of basic language datatypes (int, string, etc.) helps to build more robust and secure systems.

Although some domain primitives are project/domain specific, I found that some of them can be easily shared between projects. This repository is a library of domain primitives in Kotlin that aim to represent universal concepts so anyone may use them. It will always be incomplete so I will be adding new ones when I need it or feel it. Contributions are wellcome.

List of domain primitives

  • Year

    • vale between -9000000 and 3000
  • Email

    • value length between 5 and 254
    • value matches regular expression
  • Url

    • value length less than 2047 (Edge limit)
    • value matches regular expression
  • LangISO639

    • value length between 2 and 8
    • value matches regular expression [a-zA-Z]{2,8}
    • value in list of known lang codes
  • Isbn

    • value normalized (only numbers) length is 10 or 13
    • value is valid following ISBN10 or ISBN13 validation rules
  • Slug

    • value length less than 2000
    • value matches regular expression [a-z0-9]+(-[a-z0-9]+)*
  • PositiveQuantity

    • value greater or equal than 0
  • SHA1Hash

    • value length is 40
    • value matches regular expression [0-9a-f]{40}
  • ExceptionMessage

    • value is not blank
    • value matches regular expression [\w ,.:_\t-]+

About

A domain primitives library in Kotlin

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Languages