Skip to main content

Model

This page is giving details about the configuration of a Model.

{
name: 'model',
correlation_id: 'model_id',
schema: {
model: {
type: 'object',
properties: {
email: {
type: 'string',
description: 'Email address',
example: 'john@doe.org',
format: 'email',
}
}
}
}
}

Required

is_enabled: boolean;

Boolean indicating the current state of this model: active (true) or inactive (false).

name: string

Name of the model. Prefer a plural form like: users, badges, invoices.

correlation_field: string

Field that will be used to identify an entity in this model. Entity state, events and snapshots will all be correlated with this Field.

For example, if correlation_field = user_id, a User will have the property user_id with a unique ID as well as every event associated with a unique version number.

schema: ModelSchema

Here is the full schema defining your model with the model described as a JSON Schema and every single event associated to it.

Options

description?: string

Description of the model. Helpful to add more context in the Open API documentation or in Metabase after a Data Model synchronization.

retry_duration?: number

milliseconds

Duration in milliseconds to accept an event reduction concurrently to another event happening on the same history: entity-based or globally.

indexes?: ModelIndex[]

@see IndexSpecification + CreateIndexesOptions

Format:

{
collection: string;
fields: IndexSpecification;
opts: CreateIndexesOptions;
}

where collection is the name of the collection to apply the index on. For a model with a name users, the state collection is users, the events collection is users_events and the snapshots collection is users_snapshots.

Based on your business logic, you must define indexes on either one or several of these 3 collections.

Default indexes

By default, some indexes are automatically created to ensure correlation Id unicity or events unicity and order.

encrypted_fields?: string[]

List of fields that must be considered as sensitive and encrypted in database. Every field in this field will be automatically encrypted on any write operation. A specific decrypt action must be executed on the data to access the clear data back. A log is registered to keep track of the different accesses.

Deep notation is supported like my.sensitive.data for object:

{
my: {
sensitive: {
data: {
hash: 'xxx',
encrypted: 'xxx'
}
}
}
}

Advanced

with_default_events?: boolean

If false, default events attached to a model are removed. Those events are basically CREATED, UPDATED, PATCHED, ARCHIVED, DELETED, RESTORED and ROLLBACKED.

This is useful if you plan to apply a strict application of the Domain Driven approach excluding any non specific event.

with_global_version?: boolean

If true, the event history versioning is applied on the full collection instead of the entity.

with_blockchain_hash?: boolean

If true, blockchain hashes are generated and attached to every event stored in the Datastore. Fields used are defined below.

current_hash_field?: string

default: hash

Field used to store the current event hash.

previous_hash_field?: string

default: prev

Field used to store the previous event hash.

nonce_field?: string

default: nonce

Field used to store the nonce value.

blockchain_hash_difficulty?: number

default: 0

Difficulty used to generate the hash. 1 means that the found hash must start with a 0. 3 means that the hash must start with 000.

Higher value means harder to find a hash.

blockchain_hash_genesis?: string

default: 0000000000000000000000000000000000000000000000000000000000000000

Genesis hash used to start the blockchain.