98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package world
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.cin.su/m/Assistant/platform/ids"
|
|
)
|
|
|
|
// SemanticReference is the transport envelope used by World contracts. It is
|
|
// a reference only; it does not expose another owner's storage.
|
|
type SemanticReference = ids.SemanticRef
|
|
|
|
type PrincipalRealm string
|
|
|
|
const (
|
|
RealmPersonal PrincipalRealm = "PERSONAL"
|
|
RealmShared PrincipalRealm = "SHARED"
|
|
RealmPublic PrincipalRealm = "PUBLIC"
|
|
RealmSystem PrincipalRealm = "SYSTEM"
|
|
)
|
|
|
|
type SensitivityClass string
|
|
|
|
const (
|
|
SensitivityPublic SensitivityClass = "PUBLIC"
|
|
SensitivityPrivate SensitivityClass = "PRIVATE"
|
|
SensitivityRestricted SensitivityClass = "RESTRICTED"
|
|
SensitivitySecretReference SensitivityClass = "SECRET_REFERENCE"
|
|
)
|
|
|
|
type ValueTypeKind string
|
|
|
|
const (
|
|
ValueString ValueTypeKind = "STRING"
|
|
ValueInteger ValueTypeKind = "INTEGER"
|
|
ValueDecimal ValueTypeKind = "DECIMAL"
|
|
ValueBoolean ValueTypeKind = "BOOLEAN"
|
|
ValueTime ValueTypeKind = "TIME"
|
|
ValueDuration ValueTypeKind = "DURATION"
|
|
ValueEnum ValueTypeKind = "ENUM"
|
|
ValueReference ValueTypeKind = "REFERENCE"
|
|
ValueBinaryRef ValueTypeKind = "BINARY_REF"
|
|
ValueList ValueTypeKind = "LIST"
|
|
ValueStruct ValueTypeKind = "STRUCT"
|
|
)
|
|
|
|
type ValueField struct {
|
|
Name string
|
|
Type ValueTypeSpec
|
|
}
|
|
|
|
type ValueTypeSpec struct {
|
|
Kind ValueTypeKind
|
|
Element *ValueTypeSpec
|
|
Fields []ValueField
|
|
EnumValues []string
|
|
ReferenceKind string
|
|
}
|
|
|
|
func (s ValueTypeSpec) Validate() error {
|
|
if s.Kind == "" {
|
|
return fmt.Errorf("value type kind is required")
|
|
}
|
|
switch s.Kind {
|
|
case ValueList:
|
|
if s.Element == nil {
|
|
return fmt.Errorf("list element type is required")
|
|
}
|
|
return s.Element.Validate()
|
|
case ValueStruct:
|
|
if len(s.Fields) == 0 {
|
|
return fmt.Errorf("struct fields are required")
|
|
}
|
|
seen := map[string]struct{}{}
|
|
for _, field := range s.Fields {
|
|
if field.Name == "" {
|
|
return fmt.Errorf("struct field name is required")
|
|
}
|
|
if _, ok := seen[field.Name]; ok {
|
|
return fmt.Errorf("duplicate struct field %q", field.Name)
|
|
}
|
|
seen[field.Name] = struct{}{}
|
|
if err := field.Type.Validate(); err != nil {
|
|
return fmt.Errorf("field %s: %w", field.Name, err)
|
|
}
|
|
}
|
|
case ValueEnum:
|
|
if len(s.EnumValues) == 0 {
|
|
return fmt.Errorf("enum values are required")
|
|
}
|
|
case ValueReference:
|
|
if s.ReferenceKind == "" {
|
|
return fmt.Errorf("reference kind is required")
|
|
}
|
|
}
|
|
return nil
|
|
}
|