Form an Idea

The Idea schema format is a loose meta language with simple and flexible syntax that any transformer can use as a basis to render code. The following describes how to write an idea using the schema format.

Syntax

The syntax does not require the use of separators like commas , and colons : because the parser can logically make a determination of separations. To simplify further, only double quotes " are used to represent strings. Consider the following example.
Copy
Use the double forward slash // to add a comment. The parser will ignore anything after the slashes until the next line. The following example shows how add comments.
Copy
Idea has 6 block declarations including the following.
Every block declaration should start with one of these and each have their own block syntax (though most are similar).

Use

The block is used to import other ideas into the main idea. The syntax is as follows.
Copy
The above example imports the file into the current idea. This is assuming the file is in the same directory as the current idea. You can also import ideas from the node_modules directory in the following way.
Copy
The above example imports the file into the current idea where this file is a published package found in one of your node_modules directories. If you have a serialized idea in json format, you can import it as well like the following example.
Copy

Props

A prop is a generic property that can be defined and referenced in other props and attributes. Consider the following prop definitions.
Copy
The above example explains attributes you would put in an field. In JavaScript, the above prop would look like the following.
Copy
A prop starts with the block declaration followed by a name. A prop name is a string that starts with a capital letter followed by any letter (upper or lower case), number and underscore. The following several examples of valid and invalid prop names.
Copy
All props are represened as a key value pairs. For each pair, the key name starts with a letter (upper or lower case), followed by any letter (upper or lower case), number, and underscore. A pair starts with the key name, followed by a space, and then the value. A value can be a string, number, boolean, null, array, or object. The following examples show how to define props with different types of values.
Copy
Once a prop is defined, it can be used in other props and attributes. The following example of a model shows using the prop in an attribute.
Copy
Props can also be extracted from a plugin like the following example.
Copy

Enums

An enum is a pretermined list of values. Enums can be used as a property type. Consider the following example.
Copy

Attributes

Attributes can be attached to columns, types, and models. Attributes always start with the at symbol followed by letters, numbers and periods. Attributes can also be expressed as a function with multiple arguments. Consider the following basic attribute.
Copy
The above example is a simple attribute called . Attributes not expressed as functions like this are evaluated as . The following are examples of attribute functions.
Copy
Copy
The above examples show how to use attributes as functions. The first example is a function called with two arguments. The first argument is a number and the second is a string. The second example is a function called with an object as an argument. The object has a single key value pair.
NOTE: You can add any kind of arbitrary attribute you want in an idea file, but it is up to transformers to recognize and process it. This means you can provision future attributes.

Columns

Columns are found in the body of types and models. The column syntax starts with a name, then a type, and any combination of attributes. Consider the following example where currency is an arbitrary name, and String is a type.
Copy
Column types can be expressed as optional or multiple like the following example.
Copy
While types are technically arbitrary as well, most transformers would know how to process natural and referenced column types.

Natural Types

Transformers (like database and typesafe transformers) rely on column types that are both generic and predictable enough to expect to generate code.
  • String - A short string usually under 255 characters
  • Text - A long string usually over 255 characters
  • Number - An integer or a float
  • Integer - Strictly an integer value
  • Float - Strictly a float or decimal value
  • Boolean - Specifically or
  • Date - A Date object or valid date string
  • Datetime - A Date object or valid datetime string
  • Time - A Date object or valid time string
  • Json - An object
  • Object - An object
  • Hash - An object

Referenced Types

Types can also reference enums, other types and models. Consider the following example.
Copy

Types

A composite type is used to define specifics of a JSON column in a model. Consider the following example.
Copy
Types can also be used in models. The following example shows how to use the type in a model.
Copy

Models

A model is a representation of a database table or collection. It uses props and types. Consider the following example.
Copy

Plugins

A plugin is a way to tell Idea to run which transformers once the Idea file parses down to JSON. The following example shows how to declare a plugin.
Copy
The above example shows how to declare a plugin in the current directory where as would try to resolve to one of the following possibilities.
  • [cwd]/docs/transform.js
  • [cwd]/docs/transform/index.js
The following example shows how to declare a plugin in the node_modules directory.
Copy
The above example shows how to declare a plugin which is an Idea plugin found in the node_modules directory. Each plugin declared can accept configuration options. The following example shows how to declare a plugin with options.
Copy
The above example shows how to declare a plugin with configuration options. The options are passed as an object with key value pairs.