entity

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package entity is the shared vocabulary of the Entity Lifecycle Pattern chassis: identifier types, the Command/Query contracts, and the read-only state views seen by both the defining and calling sides.

Index

Constants

View Source
const (
	// DeleteSignalName marks an entity for deletion: drain, finalize,
	// complete.
	DeleteSignalName = "entity-delete"
	// DescribeQueryName answers DescribeOut at any time, even after the
	// workflow closed.
	DescribeQueryName = "describe"
	// SetLabelsCommandName is the built-in label-patch command every
	// entity serves: payload is map[string]string, empty values delete.
	SetLabelsCommandName = "entity-set-labels"
	// NoteSignalName carries a domain event into the entity's history —
	// a MILESTONE, not a log line: every note is a history event and
	// costs Continue-as-New budget. Streams belong in telemetry.
	NoteSignalName = "entity-note"
)

Wire names of the entity protocol: the lifecycle signal and the describe query every entity serves. Exported so that OPERATORS — a control plane driving entities it did not define in Go — can address any entity generically; typed access still goes through entclient.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command[Res any] interface {
	Name() CommandName
	Result() Res
}

Command is the contract of a tracked mutation (a Temporal Update): implemented by the user's request type.

type CommandInfo

type CommandInfo struct {
	Name    CommandName
	ReqType string
	ResType string
}

CommandInfo describes a registered command for introspection — the seed of a future manifest (contracts enumerable from the same table that dispatches).

type CommandName

type CommandName string

CommandName names a command within a kind.

type DescribeOut

type DescribeOut[Spec, State any] struct {
	Phase             Phase             `json:"phase"`
	Spec              Spec              `json:"spec"`
	State             State             `json:"state"`
	Labels            map[string]string `json:"labels,omitempty"`
	PendingCommands   int               `json:"pendingCommands"`
	MarkedForDeletion bool              `json:"markedForDeletion"`
	RunID             string            `json:"runId"`
}

DescribeOut is the answer to the built-in "describe" query: current status plus pending work, queryable at any time without blocking.

type KindName

type KindName string

KindName names an entity kind; it becomes the workflow type name and the workflow ID prefix.

func (KindName) Validate

func (k KindName) Validate() error

Validate reports whether the kind name is well-formed.

type Phase

type Phase string

Phase is the lifecycle phase of an entity, per the Entity Lifecycle Pattern: creation -> ready -> (deleting -> deleted | delete_failed).

const (
	PhaseCreating     Phase = "creating"
	PhaseReady        Phase = "ready"
	PhaseDeleting     Phase = "deleting"
	PhaseDeleted      Phase = "deleted"
	PhaseDeleteFailed Phase = "delete_failed"
	PhaseCreateFailed Phase = "create_failed"
)

Lifecycle phases.

type Query

type Query[Res any] interface {
	Name() QueryName
	Result() Res
}

Query is the contract of a read-only projection: implemented by the user's request type.

type QueryInfo

type QueryInfo struct {
	Name    QueryName
	ReqType string
	ResType string
}

QueryInfo describes a registered query for introspection.

type QueryName

type QueryName string

QueryName names a query within a kind.

type RequestID

type RequestID string

RequestID is the application-level idempotency key of one command execution; the entity dedups it even across Continue-as-New.

func ParseRequestID

func ParseRequestID(s string) (RequestID, error)

ParseRequestID validates a request id from external input.

func (RequestID) Validate

func (r RequestID) Validate() error

Validate reports whether the request id is well-formed.

type ResourceID

type ResourceID string

ResourceID identifies one resource within a kind. Workflow ID = "{kind}/{resource-id}".

func ParseResourceID

func ParseResourceID(s string) (ResourceID, error)

ParseResourceID validates a resource id from external input.

func (ResourceID) Validate

func (r ResourceID) Validate() error

Validate reports whether the resource id is well-formed.

type SelfValidator

type SelfValidator interface {
	Validate() error
}

SelfValidator is the optional method a command type may implement to reject requests before they reach Event History based on the request alone — the common case, and it needs no type parameters:

func (b BlueGreen) Validate() error { ... }

Must be pure and deterministic.

type Snapshot

type Snapshot[Spec, State any] struct {
	Phase             Phase
	Spec              Spec
	State             State
	Labels            map[string]string
	PendingCommands   int
	MarkedForDeletion bool
}

Snapshot is a read-only, by-value view of the entity handed to query handlers and command validators. Both MUST be pure: a query or validator that mutates state is a replay-determinism bug, so they never see the live state — only this copy.

type Validator

type Validator[Spec, State any] interface {
	ValidateWith(s Snapshot[Spec, State]) error
}

Validator is the state-aware variant: for validations that need the entity's current Snapshot. A command type may implement either or both; Validate runs first, then ValidateWith.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL