Locospec

Attribute Spec

Define and configure fields for your model using types, validations, generations, and options.

The attributes key in a Model Spec defines the actual fields of your data model. Each attribute describes its type, label, and optionally its validations, generations, and select options.

These are the building blocks that drive table views, forms, and validation logic across Locospec.


🔧 Basic Structure

"attributes": {
  "uuid": {
    "type": "uuid",
    "label": "ID",
    "generations": [
      {
        "type": "uuid",
        "operations": ["insert"]
      }
    ],
    "validations": [
      {
        "type": "required",
        "operations": ["insert"],
        "message": "UUID is required"
      }
    ]
  },
  "status": {
    "type": "string",
    "label": "Status",
    "options": [
      { "title": "Active", "const": "active" },
      { "title": "Inactive", "const": "inactive" }
    ]
  }
}

⚙️ Attribute Keys

KeyTypeRequiredDescription
typestringField data type (e.g. string, uuid, timestamp)
labelstringHuman-readable label for UIs
optionsarrayEnum options (for dropdowns)
generationsarrayRules for auto-generating values at runtime
validationsarrayRules for validating data during insert/update

🔢 Supported Attribute Types

TypeDescription
idAuto-incrementing primary key
uuidUniversally unique identifier
ulidLexicographically sortable ID
stringShort text
textLong text (multi-line)
timestampISO 8601 datetime string
dateDate-only (YYYY-MM-DD)
booleanTrue/false value
integerWhole numbers
decimalFloating-point numbers
jsonJSON object/array
jsonbBinary JSON (Postgres specific)
objectStructured data (used in nesting)

🎯 options

The options field defines a fixed set of allowed values for a field—typically used when the field behaves like a dropdown, or select.

This is commonly used for columns like status, type, or category, where the values come from a known list.

"status": {
  "type": "string",
  "label": "Status",
  "options": [
    { "title": "Active", "const": "active" },
    { "title": "Pending", "const": "pending" },
    { "title": "In Progress", "const": "inprogress" }
  ]
}

Each option contains:

KeyDescription
titleHuman-readable label for UI
constActual value stored in the database

🧠 Think of options as a structured enum: you control what the user sees (title) and what the system stores (const).


🔁 generations

Auto-generate field values based on context and operation.

"generations": [
  {
    "type": "uuid",
    "operations": ["insert"]
  },
  {
    "type": "uniqueSlugGenerator",
    "operations": ["insert"],
    "source": "name"
  },
  {
    "type": "datetime",
    "operations": ["insert", "update"],
    "value": "now"
  },
]
KeyDescription
typeGeneration type (uuid, uniqueSlugGenerator, datetime, stateMachine etc.)
operationsOperations during which generation occurs
source(optional) Source field for generation (e.g., slug from name)
value(optional) Value to use (e.g., "now")

validations

Define rules for validating the field during insert, update, or delete.

"validations": [
  {
    "type": "required",
    "operations": ["insert"],
    "message": "This field is required"
  },
  {
    "type": "regex:/^[a-z0-9_-]+$/",
    "operations": ["insert", "update"],
    "message": "Only lowercase, numbers, dashes and underscores allowed"
  }
]
KeyDescription
typeValidation rule (e.g. required, regex, unique)
operationsApplicable operations: insert, update, delete
messageError message if validation fails

🧪 Example: Complete Attribute

"slug": {
  "type": "string",
  "label": "Slug",
  "generations": [
    {
      "type": "slugGenerator",
      "operations": ["insert"],
      "source": "name"
    }
  ],
  "validations": [
    {
      "type": "required",
      "operations": ["insert"],
      "message": "Slug is required"
    },
    {
      "type": "unique",
      "operations": ["insert", "update"],
      "message": "Slug must be unique"
    }
  ]
}

🔎 Where This Is Used

  • Model Specs → full field definition
  • Mutator Specs → form generation + validations
  • Action Payloads → value resolution and generation
  • View & Entity Specs → UI display and formatting

📎 Spec Reference

👉 model.json#/properties/attributes

On this page