This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# continuity
|
||||
|
||||
**Owns:** Commitment and ProspectiveItem 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 continuity-owned use cases through explicit ports.
|
||||
@@ -0,0 +1,3 @@
|
||||
package domain
|
||||
|
||||
// Package domain contains continuity domain meaning only. It must not import adapters or runtime packages.
|
||||
@@ -0,0 +1,90 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
contract "git.cin.su/m/Assistant/contracts/continuity"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrProspectiveNotFound = errors.New("prospective item not found")
|
||||
ErrProspectiveRevision = errors.New("prospective item revision conflict")
|
||||
ErrInvalidTransition = errors.New("invalid prospective item transition")
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
items map[contract.ProspectiveItemID]contract.ProspectiveItem
|
||||
}
|
||||
|
||||
func Recover(items []contract.ProspectiveItem) Store {
|
||||
stored := make(map[contract.ProspectiveItemID]contract.ProspectiveItem, len(items))
|
||||
for _, item := range items {
|
||||
stored[item.ID] = item
|
||||
}
|
||||
return Store{items: stored}
|
||||
}
|
||||
|
||||
func (s *Store) Snapshot() []contract.ProspectiveItem {
|
||||
items := make([]contract.ProspectiveItem, 0, len(s.items))
|
||||
for _, item := range s.items {
|
||||
items = append(items, item)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (s *Store) Trigger(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveArmed {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
item.State = contract.ProspectiveTriggered
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) BeginRevalidation(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveTriggered {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
item.State = contract.ProspectiveRevalidating
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) FinishRevalidation(id contract.ProspectiveItemID, revision contract.ProspectiveRevision, relevant bool) (contract.ProspectiveItem, error) {
|
||||
item, err := s.current(id, revision)
|
||||
if err != nil {
|
||||
return contract.ProspectiveItem{}, err
|
||||
}
|
||||
if item.State != contract.ProspectiveRevalidating {
|
||||
return contract.ProspectiveItem{}, ErrInvalidTransition
|
||||
}
|
||||
if relevant {
|
||||
item.State = contract.ProspectiveDelivered
|
||||
} else {
|
||||
item.State = contract.ProspectiveSuppressed
|
||||
}
|
||||
item.Revision++
|
||||
s.items[id] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) current(id contract.ProspectiveItemID, revision contract.ProspectiveRevision) (contract.ProspectiveItem, error) {
|
||||
item, ok := s.items[id]
|
||||
if !ok {
|
||||
return contract.ProspectiveItem{}, ErrProspectiveNotFound
|
||||
}
|
||||
if item.Revision != revision {
|
||||
return contract.ProspectiveItem{}, ErrProspectiveRevision
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package continuity
|
||||
|
||||
// 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 continuity-owned external dependencies. Ports must be narrow and semantic.
|
||||
@@ -0,0 +1,12 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/continuity"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Save(context.Context, continuity.ProspectiveItem) error
|
||||
Load(context.Context, continuity.ProspectiveItemID) (continuity.ProspectiveItem, error)
|
||||
}
|
||||
Reference in New Issue
Block a user