Hackolade plugin for Joi
For each object in Hackolade, we've defined a set of standard properties that appear in the properties pane. But it is possible that your company wants to define and track additional properties for models, containers, entities, and attributes. Hackolade let's you do just that, by leveraging our plugin architecture (used also to integrate our modeling engine with all kinds of NoSQL document databases.)
To generate joi models from your hackolade model we first need a couple of things:
- An existing model created with the JSON target of hackolade (Note: Not required if you are building one from scratch)
- A hackolade pro license (the only one that allows generation of Joi)
- The Joi plugin for hackolade (now available in hackolade by default, you just need to install it)
Contents
-
Installation and usage
- Installation
- Plugin features / usage
- Generation with an existing JSON targeted model
- Generation through a new model created from scratch
To install the Joi plugin download hackolade first.
Open hackolade and go to Help > DB target plugin manager (or "Plugin Manager" depending on hackolade version):
Next look in the store for the Joi plugin and press on install:
Now you have successfully installed the Joi plugin.
Restart hackolade to make the plugin show when creating a new model.
Currently the plugin only supports the most simple features of Joi.
If we were to create an object with each type we will see the following: (Note: that the object type and array support multiple children because of their nature)
const schema = Joi.object().keys({
myString: Joi.string(),
myInt:
Joi.number(),
myDate: Joi.date(),
myBool: Joi.bool(),
myObject:
Joi.object().keys({}),
myArray: Joi.array().items(Joi.string()),
myNull:
Joi.valid(null).required()
});
The following properties are supported in the property pane:
Joi.Required() - required (checkbox)
Supported Types: String, int, date, bool, object, array, null (by default is always required)
Joi.Optional().allow(null) - optional (checkbox)
Supported Types: String, int, date, bool, object, array
Joi.length(), Joi.max(), Joi.min() - Min Length (Textbox), Max Length (Textbox), Length (Textbox)
Supported Types: String
Support for other Joi generation features will be based on feedback from users.
Note: A lot of other properties are in the properties pane, please ignore those for now as those are default properties of hackolade.
They will just be ignored by the Json plugin generation.
Most likely you want to generate your Joi objects from an existing JSON targeted model. You can do this fairly easily.
First open the existing model you have (the hackolade file) in VSCode or Notepad++ (or even notepad). Find the text "appTarget". You should see the following:
Now change "JSON" to "JOI".
This will allow hackolade to open up your model in the Joi context (which has the feature to generate Joi objects)
Next step is to open the document in hackolade
Open hackolade.
In the "Common Tasks" section select "Open Model".
Now look for the model you just changed and select it to open it in hackolade.
If everything went correctly you should see the model loaded in hackolade.
The next step is generating our joi models. Go to Tools → Forward-Engineer → Generate Joi Objects
You will notice you will be presented with a screen that allows you to select what you want to generate.
Select what you want to generate Joi objects for and click on submit. Now select the directory and it will generate your Joi objects successfully.
The output will put all the Joi objects in separate folders for you, if you have multiple documents.
Lastly the Joi objects might need some adjustments as some naming you might have chosen for your objects in hackolade breaks the javascript syntax. e.g. if you named an object "New Field" for instance, spaces aren't allowed on properties in javascript / typescript.
Generation through a new model is much easier as you will just need to create a need model and select the target in hackolade to be Joi.
Open hackolade and select "New Model" in "Common Tasks" section.
Next select the Joi target type (if it's not there install the plugin as mentioned at the start of this document.)
Now create the model (if you are unfamiliar on how to create a model in hackolade please read the hackolade JSON documentation)
Next follow step 3 from the previous section "Generation with an existing JSON targeted model" and go onwards from there.