diff --git a/Spec.md b/Spec.md index d806cc0..7f33606 100644 --- a/Spec.md +++ b/Spec.md @@ -6,13 +6,22 @@ For performance reasons we are to cache these data rows as well for quick lookup Events in the log are to take form of: type Event struct { - Seq int - Type "create"|"update"|"delete" - Hash string - ItemID string // uuid-v4 - EventID string // uuid-v4 - Data map[string]interface{} - Timestamp datetime + // Server generated sequence number of the event - ie when it was applied + Seq int `json:"seq"` + // Type of the event - create, update, delete, defined by the client + Type string `json:"type"` + // Hash of the event - server generated, gurantees the event was processed + Hash string `json:"hash"` + // ItemID of the item that is to be manipulated, defined by the client + ItemID string `json:"item_id"` + // EventID of the event - server generated, gurantees the event was processed + EventID string `json:"event_id"` + // Collection of the item that is to be manipulated, defined by the client + Collection string `json:"collection"` + // Data that is to be used for manipulation; for create events that's the full objects and for update events that's the diff + Data map[string]interface{} `json:"data"` + // Timestamp of the event - server generated, when the event was processed + Timestamp time.Time `json:"timestamp"` } Events are divided into 3 types, create update and delete events Create events simply create the object as given in Data @@ -33,4 +42,12 @@ Compute the hash from the dump of the current event PLUS the previous event's ha And only then apply the patch For create events that is insert objects For delete events that is mark objects as deleted -For update events get the object, apply the diff and sav the object \ No newline at end of file +For update events get the object, apply the diff and sav the object + + +--- + + +Actually for pocketbase we might want to generalize this +Maybe create a "Collection" field as well and allow the events to manipulate any table... +That way our Data isn't tied to a table... diff --git a/types.go b/types.go index 565aa6a..fd1aafa 100644 --- a/types.go +++ b/types.go @@ -3,13 +3,22 @@ package main import "time" type Event struct { - Seq int `json:"seq"` - Type string `json:"type"` - Hash string `json:"hash"` - ItemID string `json:"item_id"` - EventID string `json:"event_id"` - Data map[string]interface{} `json:"data"` - Timestamp time.Time `json:"timestamp"` + // Server generated sequence number of the event - ie when it was applied + Seq int `json:"seq"` + // Type of the event - create, update, delete, defined by the client + Type string `json:"type"` + // Hash of the event - server generated, gurantees the event was processed + Hash string `json:"hash"` + // ItemID of the item that is to be manipulated, defined by the client + ItemID string `json:"item_id"` + // EventID of the event - server generated, gurantees the event was processed + EventID string `json:"event_id"` + // Collection of the item that is to be manipulated, defined by the client + Collection string `json:"collection"` + // Data that is to be used for manipulation; for create events that's the full objects and for update events that's the diff + Data map[string]interface{} `json:"data"` + // Timestamp of the event - server generated, when the event was processed + Timestamp time.Time `json:"timestamp"` } type SLItem struct {