Guide Defining MetaTypes - osama1998H/Moca GitHub Wiki
Defining MetaTypes
JSON format, field types, naming strategies, child tables, singles, and the
_extraJSONB column.
MetaType JSON Format
A MetaType is a JSON file that defines a document type:
{
"name": "Customer",
"module": "CRM",
"naming": "by_field:customer_name",
"is_submittable": false,
"fields": [
{ "fieldname": "customer_name", "fieldtype": "Data", "label": "Customer Name", "reqd": 1, "unique": 1 },
{ "fieldname": "email", "fieldtype": "Data", "label": "Email", "options": "Email" },
{ "fieldname": "", "fieldtype": "Section Break", "label": "Address" },
{ "fieldname": "address_line_1", "fieldtype": "Data", "label": "Address Line 1" },
{ "fieldname": "city", "fieldtype": "Data", "label": "City" },
{ "fieldname": "country", "fieldtype": "Link", "label": "Country", "options": "Country" }
],
"permissions": [
{ "role": "System Manager", "read": 1, "write": 1, "create": 1, "delete": 1 }
]
}
Naming Strategies
| Strategy | Syntax | Example |
|---|---|---|
| AutoIncrement | "autoincrement" |
1, 2, 3 |
| Pattern | "pattern:INV-.YYYY.-.####" |
INV-2025-0001 |
| ByField | "by_field:customer_name" |
Acme Corp |
| ByHash | "by_hash:customer_name,email" |
a1b2c3d4 |
| UUID | "uuid" |
550e8400-e29b-... |
| Custom | "custom" |
Hook-defined |
Field Types
See Field Types Reference for all 35 field types. Common ones:
| FieldType | Stores | PostgreSQL Type |
|---|---|---|
| Data | Short text | VARCHAR(140) |
| Text | Long text | TEXT |
| Int | Integer | INTEGER |
| Float | Decimal | DOUBLE PRECISION |
| Currency | Money | NUMERIC(18,6) |
| Date | Date | DATE |
| Datetime | Timestamp | TIMESTAMP |
| Check | Boolean | BOOLEAN |
| Select | Enum | VARCHAR(140) |
| Link | Foreign key | VARCHAR(140) |
| Table | Child table | (separate table) |
Layout Fields
Non-storage fields that control UI rendering:
- Section Break -- Start a new section
- Column Break -- Start a new column within a section
- Tab Break -- Start a new tab
Child Tables
Use "fieldtype": "Table" with "options": "ChildDocType" to embed a list of child documents.
Singles
Set "is_single": true for settings-style documents that have only one instance (e.g., System Settings).
The _extra JSONB Column
Every table includes _extra JSONB for dynamic fields. Custom fields added after initial schema creation are stored here without requiring ALTER TABLE.