This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# capability
|
||||
|
||||
**Owns:** Capability, binding and health semantics.
|
||||
|
||||
See `architecture/architecture-registry.yaml` for allowed dependencies and DB schema.
|
||||
|
||||
This module may not write another owner's canonical state. Domain code does not import adapters/runtime/providers.
|
||||
@@ -0,0 +1,3 @@
|
||||
package application
|
||||
|
||||
// Package application coordinates capability-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains capability domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,41 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
var ErrInvalidHealth = errors.New("invalid capability health")
|
||||
var ErrUnsupportedHealthVersion = errors.New("unsupported capability health semantic version")
|
||||
|
||||
func ValidateHealth(health capability.Health) error {
|
||||
if health.CapabilityID == "" || health.Revision < 1 {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
switch health.SemanticVersion {
|
||||
case capability.HealthV1:
|
||||
if health.ObservedAtUnixMillis != nil {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
case capability.HealthV2:
|
||||
if health.ObservedAtUnixMillis == nil || *health.ObservedAtUnixMillis < 1 {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
default:
|
||||
return ErrUnsupportedHealthVersion
|
||||
}
|
||||
switch health.State {
|
||||
case capability.HealthAvailable:
|
||||
if health.Reason != capability.ReasonNone {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
case capability.HealthDegraded, capability.HealthUnavailable:
|
||||
if health.Reason == capability.ReasonNone || health.Reason == "" {
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
default:
|
||||
return ErrInvalidHealth
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package capability
|
||||
|
||||
// Module is an intentionally minimal V1 composition handle. Do not turn it into a God service.
|
||||
type Module struct{}
|
||||
@@ -0,0 +1,3 @@
|
||||
package ports
|
||||
|
||||
// Package ports declares capability-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,13 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
SaveHealth(context.Context, capability.Health) error
|
||||
LoadHealth(context.Context, capability.CapabilityID) (capability.Health, error)
|
||||
RebuildHealthProjection(context.Context) (int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user