Wizzi schemas

A Wizzi schema applies a type definition to the nodes of an mTree and describes the classes of a Wizzi model that can load that mTree type.

It is the core modeling tool of the Wizzi factory.

A Wizzi schema has its own Wizzi model, of type `wfschema`, implemented by the ` wizzi-core ` plugin. It is used by the artifacts of the `wizzi-core` plugin to generate the javascript modules of the Wizzi model it describes.

Wizzi schemas are codified as ITTF documents of type `wfschema`.

Sample 'rdbms' wizzi schema

                    
1 wfschema rdbms
2 e catalog
3 r table/s
4 e table
5 r column/s
6 r index/es
7 e column
8 a type
9 a caption
10 a defaultValue
11 tag default
12 e index
13 a primary
14 type boolean
15 a unique
16 type boolean
17 r column/s
Sample 'rdbms' ITTF document conformant to the above wfschema

                    
1 rdbms School
2 table Student
3 column Id
4 type integer
5 column Name
6 type string
7 index Student-PK
8 primary true
9 column Id
10 table Course
11 column Id
12 type integer
13 column Title
14 type string
15 index Student-PK
16 primary true
17 column Id
The "wfschema" schema

The wfschema, implemented by the wizzi-core plugin, is the meta model of a wizzi schema. It models a wizzi schema with the same semantic with which a wizzi schema models a Wizzi Model.

This documentation section has a circularity that may give an headache. It documents a schema that describe a schema using the same schema notation of the documented schema.

Some hints may help.

  • A wizzi schema describes a model in terms of element types, with attributes, and relations between elements. Elements can extend super elements. Relations, that do not have attributes, can be of kind parent-children (one-to-many, the default) or parent-singlechild (one-to-one).
  • Elements are described in a flat list. Relations hierarchy and element derivations are inferred from definitions.
  • The root element can be declared using the element attribute 'isRoot'. If not declared the root element is the first of the list.
  • Elements and attributes may have an optional tag attribute that defines a name alias shorter or with an easier mnemonic. wfschema examples:
    • 'e' for 'element'
    • 'a' for 'attribute'
    • 'r' for 'relation'
  • Node names of mTree nodes simply map to an element or attribute tag (or name, if a tag is not declared).
    The wfschema elements are
  • wfschema
  • exportTo
  • require
  • element
  • attribute, string, boolean, integer, float, date
  • relation
  • restrict, enum, minLength, maxLength, minValue, maxValue, regexp
  • method, function
  • parameter

wfschema element

The root element of a 'wfschema'.


                    
1 e wfschema `name`
2 r require/s
3 r exportTo/s
4 r element/s

exportTo element

An exportTo element causes the insertion in the Wizzi Model classes of the prototype functions for exporting the tree data structure of the model in the requested format

  • toJson()
  • toXml()

The entire Wizzi Model can be exported calling this methods on the root element.


                    
1 ...
2 e export-to [json|xml]

require element

A Wizzi Model can contain user defined methods and functions, that could need to import objects from other modules. This element allow to insert require statements in the generated Wizzi Model module.


                    
1 e require `import-name`
2 string declareVar `name`
3 tag declare-var
4 optional
5 default `import-name`
6 string invoke `invoke-string`
7 optional
8 string kind [module]
9 # At now we have only one kind, and this attribute is superflous.
10 # Other kinds could be added in the future.
11 optional
12 default module

The generated statement is built in this way:


                    
1 var `declareVar` = require('`import-name`')[`invoke`]

Example


                    
1 ...
2 require wizzi-utils
3 declare-var verify
4 invoke .verify
5 generates:
6 var verify = require('wizzi-utils').verify

Element element

Describes an element type of the schema.


                    
1 e element `name` [: `super-element-name`]
2 tag e
3 string super `super-element-name`
4 string tag `tag`
5 string xmlTag `tag`
6 tag xml-tag
7 boolean isAbstract
8 tag is-abstract
9 default-when-declared true
10 boolean isRoot
11 tag is-root
12 default-when-declared true
13 boolean nameIsRequired
14 tag name-is-required
15 default-when-declared true
16 boolean addToChildren
17 tag add-to-children
18 default-when-declared true
19 r attribute/s
20 r relation/s
21 r method/s

Relation element


                    
1 e relation `related-element-name`[-`plural-suffix-a`]/`plural-suffix-b`
2 # Examples
3 # r column/s (element: column, collection: columns)
4 # r propert-y/ies (element: property, collection: properties)
5 tag r
6 boolean oneToOne
7 tag one-to-one
8 default-when-declared true
9 boolean noGet
10 tag no-get
11 default-when-declared true

Example:


                    
1 ...
2 e table : dbitem
3 r column/s
4 r propert-y/ies
5 r displayLayout
6 one-to-one

related-element-name plus the eventual plural-suffix-a must give the name of an element defined in the schema (that is the related element); in the example: column, property, displayLayout.

attribute element

Describes an attribute of an element


                    
1 e attribute `name`
2 tag a
3 string tag `tag`
4 string xmlTag `tag`
5 tag xml-tag
6 string type [string|integer|float|boolean|date]
7 default string
8 string default `default-value`
9 string defaultWhenDeclared `default-value`
10 tag default-when-declared
11 boolean isDatatype
12 tag is-datatype
13 default-when-declared true
14 boolean isRequired
15 tag is-required
16 default-when-declared true
17 r restrict/s

string element


                    
1 e string `attribut-name` : attribute

boolean element


                    
1 e boolean `attribut-name` : attribute

integer element


                    
1 e integer `attribut-name` : attribute

float element


                    
1 e float `attribut-name` : attribute

date element


                    
1 e date `attribut-name` : attribute

restrict element


                    
1 e restrict
2 is-abstract

enum element


                    
1 e enum `enum-value` : restrict

maxLength element


                    
1 e maxLength `value` : restrict
2 tag max-length

minLength element


                    
1 e minLength `value` : restrict
2 tag min-length

maxValue element


                    
1 e maxValue `value` : restrict
2 tag max-value

minValue element


                    
1 e minValue `value` : restrict
2 tag min-value

regexp element


                    
1 e regexp `value` : restrict

method element

Declares a method that will be added to the element class. A method can access and manipulate the entire Wizzi Model, having access to the 'this.wzRoot()' method of the `schema-name`Base class.


                    
1 e method `name`
2 tag m
3 r param/s
4 r statement/s

param element


                    
1 e param `name`

statement element

The statement element uses a subset of the schema 'js' implemented by the plugin wizzi-js.

function element

Declares a method that will be added to the module and will be a private function for methods of the model instances.


                    
1 e function `name`
2 tag m
3 r param/s
4 r statement/s
Internal schemas

There are some common document types that have great flexibility for the definition of context data, and would be usefull to apply to those documents the templating power of mTrees without the hassle of a wizzi schema.

  • Text
  • Xml
  • Json
  • Ittf itself.

Respecting a few coding rules these type of documents can be built using the composition and template commands of ittf documents.

The production manager of the wizzi factory recognizes the following internal schemas

  • text
  • xml
  • json
  • ittf

A wizzi job or a an api call to the wizzi factory may use these schema names in any place where a wizzi schema can be used.

Json pseudo schema
Sample json ittf document

                    
1 {
2 name "v3-docs"
3 version "0.0.1"
4 description "Wizzi factory documentation."
5 scripts
6 {
7 test "mocha tests/**/*.js"
8 start "node index"
9 dependencies
10 {
11 async "^2.4.0"
12 json-stringify-safe "^5.0.1"
13 ...
14 sampleArray
15 [
16 'alfa'
17 'beta'
    Coding rules
  • The root node must be an open graph.
  • Ittf node names may contain
    • Property names.
    • Open graph for start of object.
    • Open bracket for start of array.
    • Array elements primitive values.
  • Ittf node values must contain property values when the node name is a property name, nothing in the other cases.

( It is assumed that one knows json format rules )

Xml pseudo schema
Sample xml ittf document

                    
1 profile
2 @ name ${user.name}
3 @ age ${user.age}
4 friends
5 $foreach friend in user.friends
6 friend
7 @ name ${friend.name}
8 @ age ${friend.age}
9 address
10 @ street ${user.street}
11 @ city ${user.city}
    Rules
  • Ittf node names may contain
    • element names for elements
    • simbol @ for attributes
  • Ittf node values may contain
    • nothing for elements
    • name and value separated by a blank for attributes

( It is assumed that one knows xml format rules )

Text pseudo schema

A text ittf document is a bit out of standard. It is a common text document that can break the rule of only one root node. It can use any node command or expression of an ittf document. A preprocessor transforms the text in a standard ittf tree structure. After the buildup of the mTree the 'text/document' artifact generator recreates the textual format.

Example of text mixin for a license file


                    
1 $params copy, license

The mixin transformed by the prepocessor in a standard format


                    
1 text
2 $params copy, license
3 + MIT License
4 +
5 + Copyright (c) 2015 The Wizzi Team
6 +
7 $if license === 'mit'
8 $include mit_license_text
9 $elif ...
Ittf pseudo schema

Using the ittf pseudo schema may increases the plasticity of a generation process.

We can load complex untyped ittf documents into an mTree and obtain as a result an in-memory simple tree structure of nodes with a name, a value and a childs collection, that can generate a new ittf document.

We can chain complex mTrees buildups until we get the final ittf document to load into a Wizzi Model for artifact generation.