Documentation
¶
Overview ¶
Package contracts provides the local typed contract registry used by GOWDK runtime roles.
Index ¶
- Constants
- Variables
- func ContractName[T any]() string
- func DispatchCommandEvents(ctx context.Context, sink CommandEventSink, registry *Registry, role Role, ...) error
- func EmitDomain[E any](ctx context.Context, event E) error
- func EmitIntegration[E any](ctx context.Context, event E) error
- func EmitPresentation[E any](ctx context.Context, event E) error
- func ExecuteCommand[C, R any](ctx context.Context, registry *Registry, command C) (R, error)
- func ExecuteCommandForRole[C, R any](ctx context.Context, registry *Registry, role Role, command C) (R, error)
- func ExecuteCommandToBroker[C, R any](ctx context.Context, registry *Registry, broker Broker, command C) (R, error)
- func ExecuteCommandToBrokerForRole[C, R any](ctx context.Context, registry *Registry, broker Broker, role Role, command C) (R, error)
- func ExecuteCommandToOutbox[C, R any](ctx context.Context, registry *Registry, outbox Outbox, command C) (R, error)
- func ExecuteCommandToOutboxForRole[C, R any](ctx context.Context, registry *Registry, outbox Outbox, role Role, command C) (R, error)
- func ExecuteCommandToPresentationFanout[C, R any](ctx context.Context, registry *Registry, fanout PresentationFanout, command C) (R, error)
- func ExecuteCommandToPresentationFanoutForRole[C, R any](ctx context.Context, registry *Registry, fanout PresentationFanout, role Role, ...) (R, error)
- func ExecuteJob[J any](ctx context.Context, registry *Registry, job J) error
- func ExecuteJobForRole[J any](ctx context.Context, registry *Registry, role Role, job J) error
- func ExecuteQuery[Q, R any](ctx context.Context, registry *Registry, query Q) (R, error)
- func ExecuteQueryForRole[Q, R any](ctx context.Context, registry *Registry, role Role, query Q) (R, error)
- func Is(err error, kind ErrorKind) bool
- func MarshalEventEnvelopeJSON(event EventEnvelope) ([]byte, error)
- func NewEventID() string
- func PublishDomain[E any](ctx context.Context, registry *Registry, event E) error
- func PublishDomainForRole[E any](ctx context.Context, registry *Registry, role Role, event E) error
- func PublishEnvelope(ctx context.Context, registry *Registry, event EventEnvelope) error
- func PublishEnvelopeForRole(ctx context.Context, registry *Registry, role Role, event EventEnvelope) error
- func PublishEnvelopes(ctx context.Context, registry *Registry, events []EventEnvelope) error
- func PublishEnvelopesForRole(ctx context.Context, registry *Registry, role Role, events []EventEnvelope) error
- func PublishEventsToBroker(ctx context.Context, broker Broker, events []EventEnvelope) error
- func PublishIntegration[E any](ctx context.Context, registry *Registry, event E) error
- func PublishIntegrationForRole[E any](ctx context.Context, registry *Registry, role Role, event E) error
- func PublishPresentation[E any](ctx context.Context, registry *Registry, event E) error
- func PublishPresentationForRole[E any](ctx context.Context, registry *Registry, role Role, event E) error
- func RegisterCommand[C, R any](registry *Registry, handler CommandHandler[C, R], roles ...Role) error
- func RegisterDomainEvent[E any](registry *Registry, handler EventHandler[E], roles ...Role) error
- func RegisterIntegrationEvent[E any](registry *Registry, handler EventHandler[E], roles ...Role) error
- func RegisterInvalidation[E, Q any](registry *Registry) error
- func RegisterJob[J any](registry *Registry, handler JobHandler[J], roles ...Role) error
- func RegisterPresentationEvent[E any](registry *Registry, handler EventHandler[E], roles ...Role) error
- func RegisterQuery[Q, R any](registry *Registry, handler QueryHandler[Q, R], roles ...Role) error
- func RunEventWorker(ctx context.Context, registry *Registry, source EventSource) error
- func RunEventWorkerForRole(ctx context.Context, registry *Registry, role Role, source EventSource) error
- func RunEventWorkerForRoleWithOptions(ctx context.Context, registry *Registry, role Role, source EventSource, ...) error
- func RunEventWorkerForRoleWithSeenStore(ctx context.Context, registry *Registry, role Role, source EventSource, ...) error
- func RunEventWorkerForRoleWithSeenStoreAndOptions(ctx context.Context, registry *Registry, role Role, source EventSource, ...) error
- func RunEventWorkerWithOptions(ctx context.Context, registry *Registry, source EventSource, ...) error
- func RunEventWorkerWithSeenStore(ctx context.Context, registry *Registry, source EventSource, seen SeenStore) error
- func RunEventWorkerWithSeenStoreAndOptions(ctx context.Context, registry *Registry, source EventSource, seen SeenStore, ...) error
- func SendPresentationEventsToFanout(ctx context.Context, fanout PresentationFanout, events []EventEnvelope) error
- type Broker
- type CommandEventSink
- func BrokerCommandEventSink(broker Broker) CommandEventSink
- func CompositeCommandEventSink(sinks ...CommandEventSink) CommandEventSink
- func InProcessCommandEventSink() CommandEventSink
- func OutboxCommandEventSink(outbox Outbox) CommandEventSink
- func PresentationFanoutCommandEventSink(fanout PresentationFanout) CommandEventSink
- func QueryInvalidationCommandEventSink(fanout PresentationFanout, invalidations []QueryInvalidation) CommandEventSink
- type CommandHandler
- type Error
- type ErrorKind
- type EventBatch
- type EventCategory
- type EventDecoder
- type EventEnvelope
- func CaptureCommandEvents[C, R any](ctx context.Context, registry *Registry, command C) (R, []EventEnvelope, error)
- func CaptureCommandEventsForRole[C, R any](ctx context.Context, registry *Registry, role Role, command C) (R, []EventEnvelope, error)
- func DecodeEventEnvelopeJSON(payload []byte, decoders map[string]EventDecoder) (EventEnvelope, error)
- func EnsureEventID(event EventEnvelope) EventEnvelope
- func EnsureEventIDs(events []EventEnvelope) []EventEnvelope
- type EventHandler
- type EventSource
- type EventWorkerBackoff
- type EventWorkerOption
- type EventWorkerRetry
- type JobHandler
- type Kind
- type MemorySeenStore
- type Metadata
- type Observation
- type ObservationLabels
- type ObservationName
- type Outbox
- type PresentationFanout
- type QueryHandler
- type QueryInvalidation
- type QueryInvalidationNotice
- type Registry
- type Role
- type SeenStore
- type StoredEventEnvelope
Constants ¶
const QueryInvalidationPresentationEventType = "gowdk.query.invalidate"
QueryInvalidationPresentationEventType is the browser-facing presentation event type generated when backend events invalidate query-owned regions.
Variables ¶
var ErrEventSourceClosed = errors.New("event source closed")
ErrEventSourceClosed tells RunEventWorker that the source drained cleanly.
var WorkerLogger func(message string) = func(message string) { log.Print(message) }
WorkerLogger receives dispatch failures that RunEventWorker recovered from by nacking the batch. Set it to nil to silence recovered-dispatch logging. It defaults to the standard log package.
Functions ¶
func ContractName ¶
ContractName returns the stable contract name used by registry metadata and event envelopes for T.
func DispatchCommandEvents ¶
func DispatchCommandEvents(ctx context.Context, sink CommandEventSink, registry *Registry, role Role, events []EventEnvelope) error
DispatchCommandEvents sends captured command events to sink. A nil sink uses the default in-process subscriber dispatch path.
func EmitDomain ¶
EmitDomain records a backend-owned domain event for dispatch after the current command succeeds.
func EmitIntegration ¶
EmitIntegration records a durable integration event for dispatch after the current command succeeds.
func EmitPresentation ¶
EmitPresentation records a browser-facing presentation event for dispatch after the current command succeeds.
func ExecuteCommand ¶
ExecuteCommand runs a command and dispatches events recorded with Emit* only after the command handler succeeds.
func ExecuteCommandForRole ¶
func ExecuteCommandForRole[C, R any](ctx context.Context, registry *Registry, role Role, command C) (R, error)
ExecuteCommandForRole runs a command owner for role and dispatches only matching event subscribers after the command succeeds.
func ExecuteCommandToBroker ¶
func ExecuteCommandToBroker[C, R any](ctx context.Context, registry *Registry, broker Broker, command C) (R, error)
ExecuteCommandToBroker runs a command and publishes emitted events to broker after the command handler succeeds. Subscribers are not dispatched.
func ExecuteCommandToBrokerForRole ¶
func ExecuteCommandToBrokerForRole[C, R any](ctx context.Context, registry *Registry, broker Broker, role Role, command C) (R, error)
ExecuteCommandToBrokerForRole runs a command for role and publishes emitted events to broker after the command handler succeeds.
func ExecuteCommandToOutbox ¶
func ExecuteCommandToOutbox[C, R any](ctx context.Context, registry *Registry, outbox Outbox, command C) (R, error)
ExecuteCommandToOutbox runs a command and stores emitted events in outbox after the command handler succeeds. Subscribers are not dispatched.
func ExecuteCommandToOutboxForRole ¶
func ExecuteCommandToOutboxForRole[C, R any](ctx context.Context, registry *Registry, outbox Outbox, role Role, command C) (R, error)
ExecuteCommandToOutboxForRole runs a command for role and stores emitted events in outbox after the command handler succeeds.
func ExecuteCommandToPresentationFanout ¶
func ExecuteCommandToPresentationFanout[C, R any](ctx context.Context, registry *Registry, fanout PresentationFanout, command C) (R, error)
ExecuteCommandToPresentationFanout runs a command and sends presentation events to fanout after the command handler succeeds. Subscribers are not dispatched and non-presentation events are not sent to fanout.
func ExecuteCommandToPresentationFanoutForRole ¶
func ExecuteCommandToPresentationFanoutForRole[C, R any](ctx context.Context, registry *Registry, fanout PresentationFanout, role Role, command C) (R, error)
ExecuteCommandToPresentationFanoutForRole runs a command for role and sends presentation events to fanout after the command handler succeeds.
func ExecuteJob ¶
ExecuteJob runs a registered job handler.
func ExecuteJobForRole ¶
ExecuteJobForRole runs a job handler only when it is available to role.
func ExecuteQuery ¶
ExecuteQuery runs a registered query handler.
func ExecuteQueryForRole ¶
func ExecuteQueryForRole[Q, R any](ctx context.Context, registry *Registry, role Role, query Q) (R, error)
ExecuteQueryForRole runs a query handler only when it is available to role.
func MarshalEventEnvelopeJSON ¶ added in v0.3.0
func MarshalEventEnvelopeJSON(event EventEnvelope) ([]byte, error)
MarshalEventEnvelopeJSON encodes an event envelope into the shared JSON transport shape.
func NewEventID ¶ added in v0.5.0
func NewEventID() string
NewEventID returns a process-local unique event ID suitable for durable envelope storage and worker deduplication.
func PublishDomain ¶
PublishDomain dispatches a domain event immediately.
func PublishDomainForRole ¶
PublishDomainForRole dispatches a domain event to subscribers available to role.
func PublishEnvelope ¶
func PublishEnvelope(ctx context.Context, registry *Registry, event EventEnvelope) error
PublishEnvelope dispatches one captured event envelope immediately.
func PublishEnvelopeForRole ¶
func PublishEnvelopeForRole(ctx context.Context, registry *Registry, role Role, event EventEnvelope) error
PublishEnvelopeForRole dispatches one captured event envelope to subscribers available to role.
func PublishEnvelopes ¶
func PublishEnvelopes(ctx context.Context, registry *Registry, events []EventEnvelope) error
PublishEnvelopes dispatches captured event envelopes in order.
func PublishEnvelopesForRole ¶
func PublishEnvelopesForRole(ctx context.Context, registry *Registry, role Role, events []EventEnvelope) error
PublishEnvelopesForRole dispatches captured event envelopes in order to subscribers available to role.
func PublishEventsToBroker ¶
func PublishEventsToBroker(ctx context.Context, broker Broker, events []EventEnvelope) error
PublishEventsToBroker sends captured events to broker in one ordered batch.
func PublishIntegration ¶
PublishIntegration dispatches an integration event immediately.
func PublishIntegrationForRole ¶
func PublishIntegrationForRole[E any](ctx context.Context, registry *Registry, role Role, event E) error
PublishIntegrationForRole dispatches an integration event to subscribers available to role.
func PublishPresentation ¶
PublishPresentation dispatches a presentation event immediately.
func PublishPresentationForRole ¶
func PublishPresentationForRole[E any](ctx context.Context, registry *Registry, role Role, event E) error
PublishPresentationForRole dispatches a presentation event to subscribers available to role.
func RegisterCommand ¶
func RegisterCommand[C, R any](registry *Registry, handler CommandHandler[C, R], roles ...Role) error
RegisterCommand registers one command owner. A command can have exactly one owner handler.
func RegisterDomainEvent ¶
RegisterDomainEvent registers a subscriber for a backend-owned domain event.
func RegisterIntegrationEvent ¶
func RegisterIntegrationEvent[E any](registry *Registry, handler EventHandler[E], roles ...Role) error
RegisterIntegrationEvent registers a subscriber for a durable integration event.
func RegisterInvalidation ¶ added in v0.5.0
RegisterInvalidation records that a domain event type invalidates a query type. The compiler scans this metadata to generate browser query refresh wiring; runtime callers can also inspect it through Registry.Invalidations.
func RegisterJob ¶
RegisterJob registers one background or scheduled job handler.
func RegisterPresentationEvent ¶
func RegisterPresentationEvent[E any](registry *Registry, handler EventHandler[E], roles ...Role) error
RegisterPresentationEvent registers a subscriber or fanout hook for a browser-facing presentation event. Presentation events are output only; they must not be treated as trusted domain input.
func RegisterQuery ¶
func RegisterQuery[Q, R any](registry *Registry, handler QueryHandler[Q, R], roles ...Role) error
RegisterQuery registers one readonly query handler.
func RunEventWorker ¶
func RunEventWorker(ctx context.Context, registry *Registry, source EventSource) error
RunEventWorker reads batches from source and dispatches them to worker-role subscribers until ctx is canceled or source returns ErrEventSourceClosed.
func RunEventWorkerForRole ¶
func RunEventWorkerForRole(ctx context.Context, registry *Registry, role Role, source EventSource) error
RunEventWorkerForRole reads batches from source and dispatches them to subscribers available to role. Dispatch failures that the source accepts through Nack are logged via WorkerLogger and the worker keeps consuming; it only stops when ctx ends, the source closes, or Ack/Nack fail.
func RunEventWorkerForRoleWithOptions ¶ added in v0.5.0
func RunEventWorkerForRoleWithOptions(ctx context.Context, registry *Registry, role Role, source EventSource, options ...EventWorkerOption) error
RunEventWorkerForRoleWithOptions reads batches for role with explicit worker options such as retry backoff.
func RunEventWorkerForRoleWithSeenStore ¶ added in v0.5.0
func RunEventWorkerForRoleWithSeenStore(ctx context.Context, registry *Registry, role Role, source EventSource, seen SeenStore) error
RunEventWorkerForRoleWithSeenStore reads batches for role and skips duplicate event IDs already present in seen. A nil seen store preserves the default at-least-once worker behavior.
func RunEventWorkerForRoleWithSeenStoreAndOptions ¶ added in v0.5.0
func RunEventWorkerForRoleWithSeenStoreAndOptions(ctx context.Context, registry *Registry, role Role, source EventSource, seen SeenStore, options ...EventWorkerOption) error
RunEventWorkerForRoleWithSeenStoreAndOptions reads batches for role with a seen store and explicit worker options such as retry backoff.
func RunEventWorkerWithOptions ¶ added in v0.5.0
func RunEventWorkerWithOptions(ctx context.Context, registry *Registry, source EventSource, options ...EventWorkerOption) error
RunEventWorkerWithOptions reads worker-role batches with explicit worker options such as retry backoff.
func RunEventWorkerWithSeenStore ¶ added in v0.5.0
func RunEventWorkerWithSeenStore(ctx context.Context, registry *Registry, source EventSource, seen SeenStore) error
RunEventWorkerWithSeenStore reads worker-role batches and skips duplicate event IDs already present in seen. Duplicate-only batches are acknowledged without invoking subscribers.
func RunEventWorkerWithSeenStoreAndOptions ¶ added in v0.5.0
func RunEventWorkerWithSeenStoreAndOptions(ctx context.Context, registry *Registry, source EventSource, seen SeenStore, options ...EventWorkerOption) error
RunEventWorkerWithSeenStoreAndOptions reads worker-role batches with a seen store and explicit worker options such as retry backoff.
func SendPresentationEventsToFanout ¶
func SendPresentationEventsToFanout(ctx context.Context, fanout PresentationFanout, events []EventEnvelope) error
SendPresentationEventsToFanout sends only presentation events to fanout.
Types ¶
type Broker ¶
type Broker interface {
PublishEvents(context.Context, []EventEnvelope) error
}
Broker publishes command-emitted events to an external delivery system. Implementations decide serialization, acknowledgements, and delivery policy.
type CommandEventSink ¶
type CommandEventSink interface {
HandleCommandEvents(context.Context, *Registry, Role, []EventEnvelope) error
}
CommandEventSink receives events captured from a successful command. The registry and role let sinks choose between in-process subscriber dispatch, durable storage, broker publication, or browser-facing presentation delivery.
func BrokerCommandEventSink ¶
func BrokerCommandEventSink(broker Broker) CommandEventSink
BrokerCommandEventSink returns a sink that publishes captured events to broker without dispatching local subscribers.
func CompositeCommandEventSink ¶
func CompositeCommandEventSink(sinks ...CommandEventSink) CommandEventSink
CompositeCommandEventSink returns a sink that sends the same captured event batch to each sink in order. Nil sinks are ignored.
func InProcessCommandEventSink ¶
func InProcessCommandEventSink() CommandEventSink
InProcessCommandEventSink returns a sink that dispatches captured events through the local registry with role filtering.
func OutboxCommandEventSink ¶
func OutboxCommandEventSink(outbox Outbox) CommandEventSink
OutboxCommandEventSink returns a sink that stores captured events in outbox without dispatching local subscribers.
func PresentationFanoutCommandEventSink ¶
func PresentationFanoutCommandEventSink(fanout PresentationFanout) CommandEventSink
PresentationFanoutCommandEventSink returns a sink that sends only presentation events to fanout.
func QueryInvalidationCommandEventSink ¶ added in v0.5.0
func QueryInvalidationCommandEventSink(fanout PresentationFanout, invalidations []QueryInvalidation) CommandEventSink
QueryInvalidationCommandEventSink sends one generated presentation event for query types invalidated by captured command events. Fanout errors are ignored so invalidation delivery never decides command success.
type CommandHandler ¶
Handler types accepted by the registry.
type ErrorKind ¶
type ErrorKind string
const ( ErrDuplicateHandler ErrorKind = "duplicate_handler" ErrMissingHandler ErrorKind = "missing_handler" ErrUnsupportedHandler ErrorKind = "unsupported_handler" ErrNilHandler ErrorKind = "nil_handler" ErrNoEventRecorder ErrorKind = "no_event_recorder" ErrSubscriberFailed ErrorKind = "subscriber_failed" ErrRoleNotAllowed ErrorKind = "role_not_allowed" )
type EventBatch ¶
type EventBatch struct {
Events []EventEnvelope
Ack func(context.Context) error
Nack func(context.Context, error) error
}
EventBatch is one ordered delivery batch from an outbox, queue, or broker adapter. Ack and Nack are optional adapter hooks.
type EventCategory ¶
type EventCategory string
EventCategory identifies the trust boundary for an event.
const ( DomainEvent EventCategory = "domain" IntegrationEvent EventCategory = "integration" PresentationEvent EventCategory = "presentation" )
type EventDecoder ¶ added in v0.3.0
type EventDecoder func(json.RawMessage) (any, error)
EventDecoder converts a stored JSON event value back into the typed Go value expected by subscribers.
func JSONEventDecoder ¶ added in v0.3.0
func JSONEventDecoder[T any]() EventDecoder
JSONEventDecoder registers a generic JSON decoder for a contract event type.
type EventEnvelope ¶
type EventEnvelope struct {
ID string
TraceParent string
Category EventCategory
Type string
Value any
}
EventEnvelope is a backend-owned event captured from a successful command.
func CaptureCommandEvents ¶
func CaptureCommandEvents[C, R any](ctx context.Context, registry *Registry, command C) (R, []EventEnvelope, error)
CaptureCommandEvents runs a command and returns events recorded with Emit* after the command handler succeeds. Subscribers are not dispatched.
func CaptureCommandEventsForRole ¶
func CaptureCommandEventsForRole[C, R any](ctx context.Context, registry *Registry, role Role, command C) (R, []EventEnvelope, error)
CaptureCommandEventsForRole runs a command for role and captures emitted events without dispatching subscribers.
func DecodeEventEnvelopeJSON ¶ added in v0.3.0
func DecodeEventEnvelopeJSON(payload []byte, decoders map[string]EventDecoder) (EventEnvelope, error)
DecodeEventEnvelopeJSON decodes the shared JSON transport shape and uses a registered decoder when one exists for the event type. Without a decoder the event value remains json.RawMessage.
func EnsureEventID ¶ added in v0.5.0
func EnsureEventID(event EventEnvelope) EventEnvelope
EnsureEventID returns event with a durable ID assigned when it is missing.
func EnsureEventIDs ¶ added in v0.5.0
func EnsureEventIDs(events []EventEnvelope) []EventEnvelope
EnsureEventIDs returns a copy of events where every envelope has a durable ID. Existing IDs are preserved.
func (EventEnvelope) Observation ¶
func (event EventEnvelope) Observation(name ObservationName) Observation
Observation returns a named observation for this captured event envelope.
func (EventEnvelope) ObservationForRole ¶
func (event EventEnvelope) ObservationForRole(name ObservationName, role Role) Observation
ObservationForRole returns a named observation for this captured event envelope and records the runtime role performing the operation.
func (EventEnvelope) ObservationLabels ¶
func (event EventEnvelope) ObservationLabels() ObservationLabels
ObservationLabels returns stable labels for this captured event envelope.
type EventHandler ¶
Handler types accepted by the registry.
type EventSource ¶
type EventSource interface {
ReceiveEventBatch(context.Context) (EventBatch, error)
}
EventSource receives event batches for a worker role.
type EventWorkerBackoff ¶ added in v0.5.0
type EventWorkerBackoff func(EventWorkerRetry) time.Duration
EventWorkerBackoff returns the delay before a worker consumes the next batch after EventSource accepts a Nack. Non-positive durations mean no delay.
func ConstantEventWorkerBackoff ¶ added in v0.5.0
func ConstantEventWorkerBackoff(delay time.Duration) EventWorkerBackoff
ConstantEventWorkerBackoff returns a backoff policy with the same delay for every nacked batch. Non-positive delays result in immediate retry.
type EventWorkerOption ¶ added in v0.5.0
type EventWorkerOption func(*eventWorkerOptions)
EventWorkerOption configures RunEventWorker option variants.
func WithEventWorkerBackoff ¶ added in v0.5.0
func WithEventWorkerBackoff(backoff EventWorkerBackoff) EventWorkerOption
WithEventWorkerBackoff sets the retry delay policy used after EventSource accepts a nacked batch. Nil preserves the default immediate retry behavior.
func WithEventWorkerSeenStore ¶ added in v0.5.0
func WithEventWorkerSeenStore(seen SeenStore) EventWorkerOption
WithEventWorkerSeenStore skips duplicate event IDs already present in seen. Duplicate-only batches are acknowledged without invoking subscribers. A nil seen store preserves the default at-least-once worker behavior.
type EventWorkerRetry ¶ added in v0.5.0
EventWorkerRetry describes one nacked worker delivery attempt. Attempt is a one-based count of consecutive nacked batches for the running worker.
type JobHandler ¶
Handler types accepted by the registry.
type MemorySeenStore ¶ added in v0.5.0
type MemorySeenStore struct {
// contains filtered or unexported fields
}
MemorySeenStore is a bounded in-memory SeenStore for single-process apps, local development, and tests. It is process-local and intentionally not a durable delivery guarantee.
func NewMemorySeenStore ¶ added in v0.5.0
func NewMemorySeenStore(limit int) *MemorySeenStore
NewMemorySeenStore creates a bounded in-memory SeenStore. Non-positive limits use the default window.
func (*MemorySeenStore) MarkIfNew ¶ added in v0.5.0
MarkIfNew records id and reports whether it had not been seen inside the current memory window.
type Metadata ¶
type Metadata struct {
Kind Kind
EventCategory EventCategory
Type string
Result string
Handlers int
Roles []Role
}
Metadata describes one registered contract.
func (Metadata) Observation ¶
func (metadata Metadata) Observation(name ObservationName) Observation
Observation returns a named observation for this registered contract.
func (Metadata) ObservationForRole ¶
func (metadata Metadata) ObservationForRole(name ObservationName, role Role) Observation
ObservationForRole returns a named observation for this registered contract and records the runtime role performing the operation.
func (Metadata) ObservationLabels ¶
func (metadata Metadata) ObservationLabels() ObservationLabels
ObservationLabels returns stable labels for this registered contract.
type Observation ¶
type Observation struct {
Name ObservationName
Labels ObservationLabels
}
Observation combines a stable operation name with stable contract labels.
func NewObservation ¶
func NewObservation(name ObservationName, labels ObservationLabels) Observation
NewObservation creates an observation and copies slice labels so callers can safely reuse or mutate their input values.
type ObservationLabels ¶
type ObservationLabels struct {
Kind Kind
EventCategory EventCategory
EventID string
Contract string
Result string
Role Role
Roles []Role
Handlers int
}
ObservationLabels are stable contract attributes for logs, metrics, and traces. Empty fields are intentionally omitted by callers that do not need them.
type ObservationName ¶
type ObservationName string
ObservationName is a stable operation name for contract logs, metrics, and traces. These names are intentionally independent from CLI display text.
const ( ObservationRegisterQuery ObservationName = "gowdk.contract.register.query" ObservationRegisterCommand ObservationName = "gowdk.contract.register.command" ObservationRegisterEvent ObservationName = "gowdk.contract.register.event" ObservationRegisterJob ObservationName = "gowdk.contract.register.job" ObservationExecuteQuery ObservationName = "gowdk.contract.execute.query" ObservationExecuteCommand ObservationName = "gowdk.contract.execute.command" ObservationCaptureCommand ObservationName = "gowdk.contract.capture.command" ObservationExecuteJob ObservationName = "gowdk.contract.execute.job" ObservationPublishEvent ObservationName = "gowdk.contract.publish.event" ObservationStoreCommandEvents ObservationName = "gowdk.contract.outbox.store" ObservationPublishBrokerEvents ObservationName = "gowdk.contract.broker.publish" ObservationSendPresentationEvents ObservationName = "gowdk.contract.presentation.send" ObservationWorkerReceiveEventBatch ObservationName = "gowdk.contract.worker.receive" ObservationWorkerAckEventBatch ObservationName = "gowdk.contract.worker.ack" ObservationWorkerNackEventBatch ObservationName = "gowdk.contract.worker.nack" ObservationWorkerDedupSkip ObservationName = "gowdk.contract.worker.dedup_skip" )
type Outbox ¶
type Outbox interface {
StoreEvents(context.Context, []EventEnvelope) error
}
Outbox stores command-emitted events for durable delivery. Implementations decide persistence, transactions, retries, and broker publication.
type PresentationFanout ¶
type PresentationFanout interface {
SendPresentationEvents(context.Context, []EventEnvelope) error
}
PresentationFanout sends browser-facing presentation events to a realtime transport such as SSE or WebSocket.
type QueryHandler ¶
Handler types accepted by the registry.
type QueryInvalidation ¶ added in v0.5.0
type QueryInvalidation struct {
EventCategory EventCategory
EventType string
QueryType string
}
QueryInvalidation records that a backend event invalidates a query type.
type QueryInvalidationNotice ¶ added in v0.5.0
type QueryInvalidationNotice struct {
Queries []string `json:"queries"`
Events []string `json:"events,omitempty"`
}
QueryInvalidationNotice is the browser payload sent for invalidated queries.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores typed contract handlers for one runtime.
func (*Registry) ContractsForRole ¶
ContractsForRole returns deterministic metadata for contracts available to role.
func (*Registry) Invalidations ¶ added in v0.5.0
func (registry *Registry) Invalidations() []QueryInvalidation
Invalidations returns deterministic event-to-query invalidation metadata.
type Role ¶
type Role string
Role identifies a runtime role that can execute a contract.
const ( RoleWeb Role = "web" RoleWorker Role = "worker" RoleCron Role = "cron" RoleAPI Role = "api" RoleAdmin Role = "admin" // RoleAny marks a contract as executable by every caller role, including the // untrusted web surface. It is the explicit, audited opt-in that a contract // must declare to be reachable without naming concrete roles; an empty role // set is treated as "no role may execute" rather than "any role may execute". RoleAny Role = "any" )
type SeenStore ¶ added in v0.5.0
type SeenStore interface {
Seen(context.Context, string) (bool, error)
MarkSeen(context.Context, string) error
}
SeenStore records durable event IDs that have already been successfully dispatched and acknowledged within an adapter-defined deduplication window.
type StoredEventEnvelope ¶ added in v0.3.0
type StoredEventEnvelope struct {
ID string `json:"id,omitempty"`
TraceParent string `json:"traceparent,omitempty"`
Category EventCategory `json:"category"`
Type string `json:"type"`
Value json.RawMessage `json:"value"`
}
StoredEventEnvelope is the JSON transport shape shared by contract outbox and broker adapters.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fileoutbox provides a dependency-free JSON Lines outbox adapter for runtime/contracts.
|
Package fileoutbox provides a dependency-free JSON Lines outbox adapter for runtime/contracts. |
|
Package membroker provides an in-memory broker adapter for runtime/contracts.
|
Package membroker provides an in-memory broker adapter for runtime/contracts. |
|
Package sse provides a dependency-free server-sent events presentation fanout adapter for runtime/contracts.
|
Package sse provides a dependency-free server-sent events presentation fanout adapter for runtime/contracts. |