Skip to content
Talk to our solutions team

Traits

Traits are mechanisms for grouping common features that entities should have, including shared fields with validations. Developers apply traits to entities using the inherits function.

A built-in trait in the Data API block is available in the kisai namespace and can be accessed as kisai.id. This trait includes an identification field with specific validations.

Trait Definition Example:

namespace: kisai
traits:
- name: id
fields:
- name: id
type: ulid
defaultvalue: ulid()
validations:
- type: required
- type: unique
message: id field needs to be unique
- type: final
message: id field cannot be updated

Entity Inheriting the Trait:

entities:
- name: person
inherits: kisai.id
fields:
- name: firstname
type: string
- name: middlename
type: string
- name: lastname
type: string
- name: address
type: string

When a person entity inherits kisai.id, it gains an additional id field alongside firstname, middlename, lastname, and address.

All entities created on kis.ai have fields automatically injected through the kisai.common and kisai.softdelete traits, which have applytoall set to true.

TraitFieldDescription
kisai.commoncreatedbyThe ID of the user creating the current row
kisai.commoncreatedonTimestamp when the user created the current row
kisai.commonupdatedbyThe ID of the user updating the current row
kisai.commonupdatedonTimestamp when the user updated the current row
kisai.softdeletedeletedbyThe ID of the user soft deleting the current row
kisai.softdeletedeletedonTimestamp when the user soft deleted the current row

YAML Definition of Common Traits:

traits:
- name: common
applytoall: true
fields:
- name: createdby
type: string
defaultvalue: contextget("user")
validations:
- type: final
- type: length
min: 5
max: 255
- name: createdon
type: timestamp
defaultvalue: currentTimestamp()
validations:
- type: final
- name: updatedby
type: string
computed: contextget("user")
validations:
- type: length
min: 5
max: 255
- name: updatedon
type: timestamp
computed: currentTimestamp()
- name: softdelete
applytoall: true
fields:
- name: deletedby
type: string
validations:
- type: writeonce
- type: length
min: 5
max: 255
- name: deletedon
type: timestamp
validations:
- type: writeonce