Skip to content

Traits

Traits are way to group together common features that entities should have, like common fields with validations. Developers apply traits to entities with the inherits function.

Here is a trait that is built into Data API block, which can be used for any entity. It is defined in the namespace of kisai and it can be accessed as kisai.id

Trait Definition

kisai-standard.yaml
1
namespace: kisai
2
traits:
3
- name: id
4
fields:
5
- name: id
6
type: ulid
7
defaultvalue: ulid()
8
validations:
9
- type: required
10
- type: unique
11
message: id field needs to be unique
12
- type: final
13
message: id field cannot be updated

Entity inheriting the trait

The person entity will have an additional field id along with firstname, middlename, lastname and address

person-entity.yaml
1
entities:
2
- name: person
3
inherits: kisai.id
4
fields:
5
- name: firstname
6
type: string
7
- name: middlename
8
type: string
9
- name: lastname
10
type: string
11
- name: address
12
type: string

Default traits

All entities created on the kis.ai platform have the below fields, injected. into them through the traits kisai.common and kisai.softdelete, as they have the attribute applytoall set to true.

TraitFieldDescription
kisai.commoncreatedbythis will have the id of the user creating the current row of the entity
kisai.commoncreatedonthis will have the timestamp when the user created the current row of the entity
kisai.commonupdatedbythis will have the id of the user updating the current row of the entity
kisai.commonupdatedonthis will have the timestamp when the user updated the current row of the entity
kisai.softdeletedeletedbythis will have the id of the user soft deleted the current row of the entity
kisai.softdeletedeletedonthis will have the timestamp when the user soft deleted the current row of the entity

YAML Definition of common traits

1
traits:
2
- name: common
3
applytoall: true
4
fields:
5
- name: createdby
6
type: string
7
defaultvalue: contextget("user")
8
validations:
9
- type: final
10
- type: length
11
min: 5
12
max: 255
13
- name: createdon
14
type: timestamp
15
defaultvalue: currentTimestamp()
16
validations:
17
- type: final
18
- name: updatedby
19
type: string
20
computed: contextget("user")
21
validations:
22
- type: length
23
min: 5
24
max: 255
25
- name: updatedon
26
type: timestamp
27
computed: currentTimestamp()
28
- name: softdelete
29
applytoall: true
30
fields:
31
- name: deletedby
32
type: string
33
validations:
34
- type: writeonce
35
- type: length
36
min: 5
37
max: 255
38
- name: deletedon
39
type: timestamp
40
validations:
41
- type: writeonce