Skip to content

Qwin/Joi

Repository files navigation

Joi Plugin

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.)

Hackolade Joi Plugin - Generation of Joi models

To generate joi models from your hackolade model we first need a couple of things:

  1. An existing model created with the JSON target of hackolade (Note: Not required if you are building one from scratch)
  2. A hackolade pro license (the only one that allows generation of Joi)
  3. The Joi plugin for hackolade (now available in hackolade by default, you just need to install it)

Contents

  1. Installation and usage
    1. Installation
    2. Plugin features / usage
  2. Generation with an existing JSON targeted model
  3. Generation through a new model created from scratch

Installation / usage of the Joi plugin

Installation

Step 1

To install the Joi plugin download hackolade first.

Step 2

Open hackolade and go to Help > DB target plugin manager (or "Plugin Manager" depending on hackolade version):

Step 3

Next look in the store for the Joi plugin and press on install:


Now you have successfully installed the Joi plugin.

Step 4

Restart hackolade to make the plugin show when creating a new model.

Plugin features / usage

Currently the plugin only supports the most simple features of Joi.

Joi Types Supported:

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()
});

Properties

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.


Generation with an existing JSON targeted model

Most likely you want to generate your Joi objects from an existing JSON targeted model. You can do this fairly easily.

Step 1

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)

Step 2

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.

Step 3

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 created from scratch

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.

Step 1

Open hackolade and select "New Model" in "Common Tasks" section.

Step 2

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)

Step 3

Next follow step 3 from the previous section "Generation with an existing JSON targeted model" and go onwards from there.