feat: fn_operations library — entities, relations, types_snapshot con FTS y ciclos
Paquete Go completo con modelos (Entity, Relation, RelationInput, TypeSnapshot), DB SQLite con WAL + FTS5 en entities, CRUD para las 4 tablas, validacion de integridad, deteccion de ciclos solo en relaciones causales (via != ''), y operaciones de alto nivel con snapshot automatico de tipos del registry. 9 tests, todos pasan.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package fn_operations
|
||||
|
||||
import "time"
|
||||
|
||||
// EntityStatus represents the lifecycle state of an entity.
|
||||
type EntityStatus string
|
||||
|
||||
const (
|
||||
StatusActive EntityStatus = "active"
|
||||
StatusStale EntityStatus = "stale"
|
||||
StatusCorrupted EntityStatus = "corrupted"
|
||||
StatusArchived EntityStatus = "archived"
|
||||
)
|
||||
|
||||
// RelationStatus represents the lifecycle state of a relation.
|
||||
type RelationStatus string
|
||||
|
||||
const (
|
||||
RelDesigned RelationStatus = "designed"
|
||||
RelImplemented RelationStatus = "implemented"
|
||||
RelTested RelationStatus = "tested"
|
||||
RelRunning RelationStatus = "running"
|
||||
RelDeprecated RelationStatus = "deprecated"
|
||||
)
|
||||
|
||||
// Direction represents the directionality of a relation.
|
||||
type Direction string
|
||||
|
||||
const (
|
||||
DirUnidirectional Direction = "unidirectional"
|
||||
DirBidirectional Direction = "bidirectional"
|
||||
DirInverse Direction = "inverse"
|
||||
)
|
||||
|
||||
// Entity is a concrete instance of a registry type within a project context.
|
||||
type Entity struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
TypeRef string `json:"type_ref"`
|
||||
Status EntityStatus `json:"status"`
|
||||
Description string `json:"description"`
|
||||
Domain string `json:"domain"`
|
||||
Tags []string `json:"tags"`
|
||||
Source string `json:"source"`
|
||||
Metadata map[string]any `json:"metadata"`
|
||||
Notes string `json:"notes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Relation describes how one entity connects to or transforms into another.
|
||||
type Relation struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
FromEntity string `json:"from_entity"`
|
||||
ToEntity string `json:"to_entity"`
|
||||
Via string `json:"via"`
|
||||
Description string `json:"description"`
|
||||
Purity string `json:"purity"`
|
||||
Direction Direction `json:"direction"`
|
||||
Weight *float64 `json:"weight"`
|
||||
Status RelationStatus `json:"status"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
EndedAt *time.Time `json:"ended_at"`
|
||||
Order *int `json:"order"`
|
||||
Tags []string `json:"tags"`
|
||||
Notes string `json:"notes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// RelationInput represents one input entity in a multi-input relation.
|
||||
type RelationInput struct {
|
||||
ID string `json:"id"`
|
||||
RelationID string `json:"relation_id"`
|
||||
EntityID string `json:"entity_id"`
|
||||
Role string `json:"role"`
|
||||
Order *int `json:"order"`
|
||||
}
|
||||
|
||||
// TypeSnapshot is an immutable copy of a registry type at point of use.
|
||||
type TypeSnapshot struct {
|
||||
ID string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
Lang string `json:"lang"`
|
||||
Algebraic string `json:"algebraic"`
|
||||
Definition string `json:"definition"`
|
||||
Description string `json:"description"`
|
||||
SnappedAt time.Time `json:"snapped_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user