What is Vet?
Vet is a component of the Zuu framework designed to provide all the commons needed.
Want to contribute?
The vet in a zoo is like a... umm.... Whatever! Vet contains everything that all the other
ainmals packages might need. This includes a global framework wide Event Bus with all the events handlers, custom events, customs local wide Event buses, configuration managers and configuration injectors, dependency injection, namespacing and scoping (ex: Singleton patterns already covered), debugging, debugger tags and log streams, async runtime management and long lasting tasks also, time tools, string formating tools, platform tools and other small tools.
You can run a scoped async task using:
Runtime.scoped runs an async task in a scope (in this case
null) and it returns a
Promise that resolves when the task returns.
The events system consists of a
AbstractEvent and the
AbstractEventListener<T>. There is also a global instance of
EventBus used for framework wide event listening.
The Debugger connects to the Event Bus and emits
ErrorEvents via the static methods that is provides
Debugger.error. Vet provides some default event listeners for the Debugger events that emmit the event to the
STDERR. You can register those listeners using
Debugger.defaults static method.
It also provides log tags that act like template strings fromatters (check typescript docs for more ;)) to add metadata to your logs streams. For example the next snippet:
Debugger.defaults;;;Debugger.logtag`Here's a random value: !`;
produces the following output:
(tag-tag-tag): Here's a random value: 1298304!
Vet is onored to present to you, the world simplest Dependency Injection Container and tooling. No need to specify the providers (you can if you want...), no need to specify the scopes (you can if you want...), only specify where you want your dependency to be injected using the
@Inject decorator and it will automagically lazy load (will be provided only when needed) your dependency.
For example this script
produces the following output
(needed-resource-1): Used! (needed-resource-2): Used!
As you can see it creates the resources even if they are nested!
Also you can scope resources! Vet comes out of the box with one scope: Singleton. You can use a scope like so:
The sscript above produces the following output
(needed-resource): Constructed! 0 (needed-resource): Used! (needed-resource): Used!
Vet's configuration is an subcase of the dependency injector. It finds, caches and auto reloads the configurations needed. The onfiguration files need to have a JSON format and the
.config.json extension. They can be placed anywhere in the project structure! For example to load the config from
app.config.json you can use:
If you want to autoreload the config when changes occur, you can pass
true as the second parameter to the
Vet also provides a
ConfigurationManager class used to extract, cache, invalidate, inflate and parse configurations. It can also extract the configuration values from the env using