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.
Overview
Section titled “Overview”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: kisaitraits:- 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 updatedEntity 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: stringWhen a person entity inherits kisai.id, it gains an additional id field alongside firstname, middlename, lastname, and address.
Default Traits
Section titled “Default Traits”All entities created on kis.ai have fields automatically injected through the kisai.common and kisai.softdelete traits, which have applytoall set to true.
| Trait | Field | Description |
|---|---|---|
| kisai.common | createdby | The ID of the user creating the current row |
| kisai.common | createdon | Timestamp when the user created the current row |
| kisai.common | updatedby | The ID of the user updating the current row |
| kisai.common | updatedon | Timestamp when the user updated the current row |
| kisai.softdelete | deletedby | The ID of the user soft deleting the current row |
| kisai.softdelete | deletedon | Timestamp 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