Library root
This project and documentation are work in progress
Example code: src/lib/index
The library root exports two things:
a
createLibrary
functiona bunch of types
createLibrary
This function is used in each app to instantiate a library from a set of adapters.
So, the adapter essentially maps over the set of operations and calls wrapAdapter
(discussed in the last chapter).
The resulting type looks like this:
So, to recap on how this works - taking as example calling user.add
-
We call
user.add
with the user input params (name, address, etc) and any adapter params (an object of things that might be used by the adapters).The function created by
wrapAdapter
calls the adapter passed intocreateLibrary
That adapter may be a merged adapter calling all the others
Now the resulting context is passed to the operation
The operation does its business and either returns the output, or throws an error
Exactly how adapters work is documented in the next chapter.
Other exports
In the example code we've exported quite a few types from Lib:
Exporting the Ctx Type helps us type our adapters
Exporting Entities Types lets us use the library in a type-safe way
Exporting Errors Types lets us do useful things with typed errors
Exporting Event Types lets us read from events in a safe way
Exporting mergeAdapters is necessary for any apps
(Obviously for JS projects only mergeAdapters is needed)
Now we have a library
The library is essentially a unit of 'pure' code - that is, all our domain operations, without side effects. It's now ready to be given adapters to emit outputs, and passed to bindings to receive inputs from the outside world.
Last updated