Files
mesh/sync_validation.go
T

78 lines
2.6 KiB
Go

// Code generated by zi2go from sync_validation.zi. DO NOT EDIT.
package main
import slog "log/slog"
// #import std_go_types
// #import sync_types
func SyncValidation_Validate(database *Database, context Context, request SyncRequest) Error {
if request.AppID != "" {
var value_0 bool = Identity_ValidNamespace(request.AppID)
if !value_0 {
return StdErrorsGo_New("invalid app_id")
}
selected := AppStore_ByID(database, context, request.AppID)
if selected.Error != nil {
return selected.Error
}
if !selected.Found {
return StdErrorsGo_New("unknown app_id")
}
if selected.Value.Status != "active" {
return StdErrorsGo_New("app_id inactive")
}
var value_1 bool = request.ProtocolVersion >= int(6) && selected.Value.ManifestExpiresAt > 0
var value_2 bool = value_1
if value_2 {
var value_3 bool = StdTimeGo_Unix(StdTimeGo_Now()) > selected.Value.ManifestExpiresAt
value_2 = value_3
}
if value_2 {
return StdErrorsGo_New("app manifest expired")
}
if request.ProtocolVersion < int(6) {
legacy := AppStore_AllowsLegacyProtocol(database, context, request.AppID, request.ProtocolVersion)
if legacy.Error != nil {
return legacy.Error
}
if !legacy.Value {
return StdErrorsGo_New("legacy protocol not allowed for app_id")
}
}
}
if request.ProtocolVersion >= int(6) && request.AppID == "" {
return StdErrorsGo_New("app_id required")
}
{
value_4 := request.EncryptedRecords[:]
if int64(0) < 0 || int64(int64(len(value_4))) < int64(0) || int64(int64(len(value_4))) > int64(len(value_4)) {
panic("slice range out of bounds")
}
loop_view_30 := value_4[0:int64(len(value_4)):int64(len(value_4))]
loop_count_30 := int64(len(loop_view_30))
var loop_cursor_30 int64 = 0
for loop_cursor_30 < loop_count_30 {
loop_index_30 := loop_cursor_30
record := loop_view_30[loop_index_30]
var value_5 bool = EncryptedRecord_ValidForProtocol(record, request.ProtocolVersion)
if !value_5 {
return StdErrorsGo_New("invalid encrypted record")
}
if request.AppID != "" {
ownership := AppStore_OwnsCollection(database, context, request.AppID, record.Collection)
if ownership.Error != nil {
return ownership.Error
}
if !ownership.Value {
if request.ProtocolVersion >= int(6) {
return StdErrorsGo_New("encrypted record collection is not registered for app_id")
}
slog.Warn("sync request used unregistered app collection", "app_id", LogSafety_LogText(request.AppID), "collection", LogSafety_LogText(record.Collection), "mode", "compat")
}
}
loop_cursor_30++
}
}
return nil
}