Skip to content

Commit 668228c

Browse files
committed
docs: starting to extend validation docs.
1 parent d4608db commit 668228c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The process layer contains use cases, that model your process.
5858
In the domain layer there are supertypes to model the domain, such as entities, records, value objects and enumerations.
5959
The domain layer also knows the repository layer supertype, for handling instances of entities and structs.
6060

61-
## Entities
61+
### Entities
6262
Using **easy**, your entities, as described in domain driven design, inherit from the `Entity` class. This gives your entities identity. The default implementation of `Entity` provides a generated `id` property (it's a UUID by default).
6363

6464
All classes that inherit from `Record` or `Entity` will have an internal object called `state`. Normally, the state of an object is passed to it during construction. Using this internal object `state` allows for easy mapping of the content of an entity, which is usually JSON, to its properties. We prefer to keep our entities immutable. Properties therefore can be readonly. An update to an object is considered a state change and should therefore always return a new instance of the entity, instead of modifying the state of the current instance.
@@ -76,7 +76,7 @@ An example of an entity is the `Movie` class below. Here the content of the obje
7676

7777
Some of the properties of `Movie` have decorators, such as `@required`. These decorators can be used to validate the object, using the separate `validate()` function.
7878

79-
## Enumerables
79+
### Enumerables
8080
Most modern programming languages support the use of enumerables. The goal of an enumerable is to allow only a limited set of values to be chosen for a particular property or passed as a parameter of a function, or its return type. Although this seems trivial, there are some drawbacks to using enumerables.
8181

8282
First of all, in most language, you can not inherit from enumerables. As a result, if you define an enumerable in a library, and would like to add values to it in another repository, this is not possible. If you would, as we do in **easy** support a list of scopes, we could have created an enumerable `Scope`, with the scopes we see. However, if you use **easy** and would like to add your own scopes, this is not possible with a default enumerable.
@@ -106,19 +106,23 @@ All **easy** microservices evolve around their part of the total business domain
106106

107107
To assure that such an aggregate is valid, when persisted, it is validated, usually starting from the *aggregate root*. In most cases, the aggregate root is the entity that is also the resource that requests are about, and in most often it is also the name of the microservice itself.
108108

109+
### Validate
109110
The **easy** framework supplies a nice and easy mechanism for validating instances of the microservice's aggregate. We supply to easy-to-use functions, named `validate(subject?: unknown): Results` and `validateReject = <T>(subject?: T): Promise<T>`. Although you can pass any object to these functions, in general, you will pass the aggregate root as an argument.
110111

111112
validate = (dev: Developer): Results => validate(dev);
112113

113114
The `validate()` function will validate its `subject`, and recursively the subjects properties. The outcome of this validation is always a `Results` object, with a list of shortcomings (in its `results` property) of the subject. The `Results` object also has a property `isValid`, which is set to `true` if the subject is valid, or to `false` when it is not.
114115

116+
### Constraints
117+
The easiest way to validate objects is to use constraints.
118+
115119
# Data
116120
It is the responsibility of the classes in the data layer to fetch and deliver data from outside to the microservices. This data can come from e.g. a file system, relational and other types of databases (we prefer document databases), or from other services on your domain, or from services outside your domain. Classes performing this function are called gateways.
117121

118122
# Utilities
119123
Additionally, this library contains utility classes for standardizing e.g. uri's, and ids, constructors, lists, queries, and errors. Quite often these are constructed as monads, which renders robust code.
120124

121-
## When
125+
### When
122126
The `When` class is a utility that is usually exposed through the `when()` function. It can be used to make validations in promises a little easier such as the following example.
123127

124128
update = (json: Json): Promise<T> =>

0 commit comments

Comments
 (0)