Documentation
¶
Overview ¶
Package events provides domain event types and a dispatcher for the ORLY relay. Domain events represent significant occurrences in the system that other components may want to react to, enabling loose coupling between components.
Index ¶
- Constants
- func AllEventTypes() []string
- func SetGlobal(d *Dispatcher)
- type ACLMembershipChanged
- type Base
- type ClusterMembershipChanged
- type ConnectionClosed
- type ConnectionOpened
- type Dispatcher
- func (d *Dispatcher) OnACLMembershipChanged(handler func(*ACLMembershipChanged))
- func (d *Dispatcher) OnEventDeleted(handler func(*EventDeleted))
- func (d *Dispatcher) OnEventSaved(handler func(*EventSaved))
- func (d *Dispatcher) OnFollowListUpdated(handler func(*FollowListUpdated))
- func (d *Dispatcher) OnMemberJoined(handler func(*MemberJoined))
- func (d *Dispatcher) OnMemberLeft(handler func(*MemberLeft))
- func (d *Dispatcher) OnPolicyConfigUpdated(handler func(*PolicyConfigUpdated))
- func (d *Dispatcher) OnUserAuthenticated(handler func(*UserAuthenticated))
- func (d *Dispatcher) Publish(event DomainEvent)
- func (d *Dispatcher) PublishAsync(event DomainEvent) bool
- func (d *Dispatcher) Stats() DispatcherStats
- func (d *Dispatcher) Stop()
- func (d *Dispatcher) Subscribe(s Subscriber)
- func (d *Dispatcher) Unsubscribe(s Subscriber)
- type DispatcherConfig
- type DispatcherStats
- type DomainEvent
- type EventDeleted
- type EventSaved
- type FollowListUpdated
- type MemberJoined
- type MemberLeft
- type PolicyConfigUpdated
- type PolicyFollowsUpdated
- type RelayGroupConfigChanged
- type Subscriber
- type SubscriberFunc
- type SubscriptionClosed
- type SubscriptionCreated
- type SyncSerialUpdated
- type UserAuthenticated
Constants ¶
const ACLMembershipChangedType = "acl.membership.changed"
ACLMembershipChangedType is the event type for ACLMembershipChanged.
const ClusterMembershipChangedType = "sync.cluster.membership.changed"
ClusterMembershipChangedType is the event type for ClusterMembershipChanged.
const ConnectionClosedType = "connection.closed"
ConnectionClosedType is the event type for ConnectionClosed.
const ConnectionOpenedType = "connection.opened"
ConnectionOpenedType is the event type for ConnectionOpened.
const EventDeletedType = "event.deleted"
EventDeletedType is the event type for EventDeleted.
const EventSavedType = "event.saved"
EventSavedType is the event type for EventSaved.
const FollowListUpdatedType = "acl.followlist.updated"
FollowListUpdatedType is the event type for FollowListUpdated.
const MemberJoinedType = "nip43.member.joined"
MemberJoinedType is the event type for MemberJoined.
const MemberLeftType = "nip43.member.left"
MemberLeftType is the event type for MemberLeft.
const PolicyConfigUpdatedType = "policy.config.updated"
PolicyConfigUpdatedType is the event type for PolicyConfigUpdated.
const PolicyFollowsUpdatedType = "policy.follows.updated"
PolicyFollowsUpdatedType is the event type for PolicyFollowsUpdated.
const RelayGroupConfigChangedType = "sync.relaygroup.changed"
RelayGroupConfigChangedType is the event type for RelayGroupConfigChanged.
const SubscriptionClosedType = "subscription.closed"
SubscriptionClosedType is the event type for SubscriptionClosed.
const SubscriptionCreatedType = "subscription.created"
SubscriptionCreatedType is the event type for SubscriptionCreated.
const SyncSerialUpdatedType = "sync.serial.updated"
SyncSerialUpdatedType is the event type for SyncSerialUpdated.
const UserAuthenticatedType = "auth.user.authenticated"
UserAuthenticatedType is the event type for UserAuthenticated.
Variables ¶
This section is empty.
Functions ¶
func AllEventTypes ¶
func AllEventTypes() []string
AllEventTypes returns all registered event type constants.
func SetGlobal ¶
func SetGlobal(d *Dispatcher)
SetGlobal sets the global dispatcher instance. This should be called early in application startup if custom config is needed.
Types ¶
type ACLMembershipChanged ¶
type ACLMembershipChanged struct {
Base
Pubkey []byte // The affected pubkey
PrevLevel string // Previous access level
NewLevel string // New access level
Reason string // Reason for the change
}
ACLMembershipChanged is emitted when a pubkey's access level changes.
func NewACLMembershipChanged ¶
func NewACLMembershipChanged(pubkey []byte, prevLevel, newLevel, reason string) *ACLMembershipChanged
NewACLMembershipChanged creates a new ACLMembershipChanged domain event.
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base provides common fields for all domain events.
func (Base) OccurredAt ¶
OccurredAt returns when the event occurred.
type ClusterMembershipChanged ¶
type ClusterMembershipChanged struct {
Base
Event *event.E // The kind 39108 event
Action string // "join" or "leave"
}
ClusterMembershipChanged is emitted when cluster membership changes.
func NewClusterMembershipChanged ¶
func NewClusterMembershipChanged(ev *event.E, action string) *ClusterMembershipChanged
NewClusterMembershipChanged creates a new ClusterMembershipChanged domain event.
type ConnectionClosed ¶
type ConnectionClosed struct {
Base
ConnectionID string // Unique connection identifier
Duration time.Duration // How long the connection was open
EventsReceived int // Number of events received
EventsPublished int // Number of events published
}
ConnectionClosed is emitted when a WebSocket connection is closed.
func NewConnectionClosed ¶
func NewConnectionClosed(connID string, duration time.Duration, received, published int) *ConnectionClosed
NewConnectionClosed creates a new ConnectionClosed domain event.
type ConnectionOpened ¶
type ConnectionOpened struct {
Base
ConnectionID string // Unique connection identifier
RemoteAddr string // Client IP:port
}
ConnectionOpened is emitted when a new WebSocket connection is established.
func NewConnectionOpened ¶
func NewConnectionOpened(connID, remoteAddr string) *ConnectionOpened
NewConnectionOpened creates a new ConnectionOpened domain event.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher publishes domain events to subscribers.
func Global ¶
func Global() *Dispatcher
Global returns the global dispatcher instance. Creates one with default config if not already created.
func NewDispatcher ¶
func NewDispatcher(cfg DispatcherConfig) *Dispatcher
NewDispatcher creates a new event dispatcher.
func (*Dispatcher) OnACLMembershipChanged ¶
func (d *Dispatcher) OnACLMembershipChanged(handler func(*ACLMembershipChanged))
OnACLMembershipChanged subscribes to ACLMembershipChanged events.
func (*Dispatcher) OnEventDeleted ¶
func (d *Dispatcher) OnEventDeleted(handler func(*EventDeleted))
OnEventDeleted subscribes to EventDeleted events.
func (*Dispatcher) OnEventSaved ¶
func (d *Dispatcher) OnEventSaved(handler func(*EventSaved))
OnEventSaved subscribes to EventSaved events.
func (*Dispatcher) OnFollowListUpdated ¶
func (d *Dispatcher) OnFollowListUpdated(handler func(*FollowListUpdated))
OnFollowListUpdated subscribes to FollowListUpdated events.
func (*Dispatcher) OnMemberJoined ¶
func (d *Dispatcher) OnMemberJoined(handler func(*MemberJoined))
OnMemberJoined subscribes to MemberJoined events.
func (*Dispatcher) OnMemberLeft ¶
func (d *Dispatcher) OnMemberLeft(handler func(*MemberLeft))
OnMemberLeft subscribes to MemberLeft events.
func (*Dispatcher) OnPolicyConfigUpdated ¶
func (d *Dispatcher) OnPolicyConfigUpdated(handler func(*PolicyConfigUpdated))
OnPolicyConfigUpdated subscribes to PolicyConfigUpdated events.
func (*Dispatcher) OnUserAuthenticated ¶
func (d *Dispatcher) OnUserAuthenticated(handler func(*UserAuthenticated))
OnUserAuthenticated subscribes to UserAuthenticated events.
func (*Dispatcher) Publish ¶
func (d *Dispatcher) Publish(event DomainEvent)
Publish sends an event to all matching subscribers synchronously. This blocks until all subscribers have processed the event.
func (*Dispatcher) PublishAsync ¶
func (d *Dispatcher) PublishAsync(event DomainEvent) bool
PublishAsync sends an event to be processed asynchronously. This returns immediately and the event is processed in a background goroutine. Returns true if the event was queued, false if the queue is full.
func (*Dispatcher) Stats ¶
func (d *Dispatcher) Stats() DispatcherStats
Stats returns dispatcher statistics.
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop stops the dispatcher and waits for pending events to be processed.
func (*Dispatcher) Subscribe ¶
func (d *Dispatcher) Subscribe(s Subscriber)
Subscribe adds a subscriber to receive events.
func (*Dispatcher) Unsubscribe ¶
func (d *Dispatcher) Unsubscribe(s Subscriber)
Unsubscribe removes a subscriber.
type DispatcherConfig ¶
type DispatcherConfig struct {
// AsyncBufferSize is the buffer size for async event delivery.
// Default: 1000
AsyncBufferSize int
}
DispatcherConfig configures the dispatcher.
func DefaultDispatcherConfig ¶
func DefaultDispatcherConfig() DispatcherConfig
DefaultDispatcherConfig returns the default dispatcher configuration.
type DispatcherStats ¶
type DispatcherStats struct {
EventsPublished int64
EventsDropped int64
SubscriberCount int
QueueSize int
QueueCapacity int
}
DispatcherStats contains dispatcher statistics.
type DomainEvent ¶
type DomainEvent interface {
// OccurredAt returns when the event occurred.
OccurredAt() time.Time
// EventType returns a string identifier for the event type.
EventType() string
}
DomainEvent is the base interface for all domain events.
type EventDeleted ¶
type EventDeleted struct {
Base
EventID []byte // The deleted event ID
DeletedBy []byte // Pubkey that requested deletion
Serial uint64 // The serial of the deleted event
}
EventDeleted is emitted when a Nostr event is deleted.
func NewEventDeleted ¶
func NewEventDeleted(eventID, deletedBy []byte, serial uint64) *EventDeleted
NewEventDeleted creates a new EventDeleted domain event.
type EventSaved ¶
type EventSaved struct {
Base
Event *event.E // The saved event
Serial uint64 // The assigned serial number
IsAdmin bool // Whether the author is an admin
IsOwner bool // Whether the author is an owner
}
EventSaved is emitted when a Nostr event is successfully saved to the database.
func NewEventSaved ¶
func NewEventSaved(ev *event.E, serial uint64, isAdmin, isOwner bool) *EventSaved
NewEventSaved creates a new EventSaved domain event.
type FollowListUpdated ¶
type FollowListUpdated struct {
Base
AdminPubkey []byte // The admin whose follow list changed
AddedFollows [][]byte // Pubkeys that were added
RemovedFollows [][]byte // Pubkeys that were removed
}
FollowListUpdated is emitted when an admin's follow list changes.
func NewFollowListUpdated ¶
func NewFollowListUpdated(adminPubkey []byte, added, removed [][]byte) *FollowListUpdated
NewFollowListUpdated creates a new FollowListUpdated domain event.
type MemberJoined ¶
type MemberJoined struct {
Base
Pubkey []byte // The new member's pubkey
InviteCode string // The invite code used (if any)
}
MemberJoined is emitted when a new member joins via NIP-43.
func NewMemberJoined ¶
func NewMemberJoined(pubkey []byte, inviteCode string) *MemberJoined
NewMemberJoined creates a new MemberJoined domain event.
type MemberLeft ¶
MemberLeft is emitted when a member leaves via NIP-43.
func NewMemberLeft ¶
func NewMemberLeft(pubkey []byte) *MemberLeft
NewMemberLeft creates a new MemberLeft domain event.
type PolicyConfigUpdated ¶
type PolicyConfigUpdated struct {
Base
UpdatedBy []byte // Pubkey that made the update
Changes map[string]interface{} // Changed configuration keys
}
PolicyConfigUpdated is emitted when the policy configuration changes.
func NewPolicyConfigUpdated ¶
func NewPolicyConfigUpdated(updatedBy []byte, changes map[string]interface{}) *PolicyConfigUpdated
NewPolicyConfigUpdated creates a new PolicyConfigUpdated domain event.
type PolicyFollowsUpdated ¶
type PolicyFollowsUpdated struct {
Base
AdminPubkey []byte // The admin whose follows were processed
FollowCount int // Number of follows in the updated list
Follows [][]byte // The follow pubkeys (may be nil for large lists)
}
PolicyFollowsUpdated is emitted when policy follow lists are refreshed.
func NewPolicyFollowsUpdated ¶
func NewPolicyFollowsUpdated(adminPubkey []byte, followCount int, follows [][]byte) *PolicyFollowsUpdated
NewPolicyFollowsUpdated creates a new PolicyFollowsUpdated domain event.
type RelayGroupConfigChanged ¶
RelayGroupConfigChanged is emitted when relay group configuration changes.
func NewRelayGroupConfigChanged ¶
func NewRelayGroupConfigChanged(ev *event.E) *RelayGroupConfigChanged
NewRelayGroupConfigChanged creates a new RelayGroupConfigChanged domain event.
type Subscriber ¶
type Subscriber interface {
// Handle processes the given domain event.
Handle(event DomainEvent)
// Supports returns true if this subscriber handles the given event type.
Supports(eventType string) bool
}
Subscriber handles domain events.
type SubscriberFunc ¶
type SubscriberFunc struct {
// contains filtered or unexported fields
}
SubscriberFunc is a function that can be used as a Subscriber.
func NewSubscriberForAll ¶
func NewSubscriberForAll(handle func(DomainEvent)) *SubscriberFunc
NewSubscriberForAll creates a subscriber that handles all event types.
func NewSubscriberForTypes ¶
func NewSubscriberForTypes(handle func(DomainEvent), types ...string) *SubscriberFunc
NewSubscriberForTypes creates a subscriber that handles specific event types.
func NewSubscriberFunc ¶
func NewSubscriberFunc(handle func(DomainEvent), supports func(string) bool) *SubscriberFunc
NewSubscriberFunc creates a new SubscriberFunc.
func (*SubscriberFunc) Handle ¶
func (s *SubscriberFunc) Handle(event DomainEvent)
Handle implements Subscriber.
func (*SubscriberFunc) Supports ¶
func (s *SubscriberFunc) Supports(eventType string) bool
Supports implements Subscriber.
type SubscriptionClosed ¶
type SubscriptionClosed struct {
Base
SubscriptionID string // The subscription ID
ConnectionID string // The connection this subscription belonged to
EventsMatched int // Number of events that matched this subscription
}
SubscriptionClosed is emitted when a subscription is closed.
func NewSubscriptionClosed ¶
func NewSubscriptionClosed(subID, connID string, eventsMatched int) *SubscriptionClosed
NewSubscriptionClosed creates a new SubscriptionClosed domain event.
type SubscriptionCreated ¶
type SubscriptionCreated struct {
Base
SubscriptionID string // The subscription ID from REQ
ConnectionID string // The connection this subscription belongs to
FilterCount int // Number of filters in the subscription
}
SubscriptionCreated is emitted when a new REQ subscription is created.
func NewSubscriptionCreated ¶
func NewSubscriptionCreated(subID, connID string, filterCount int) *SubscriptionCreated
NewSubscriptionCreated creates a new SubscriptionCreated domain event.
type SyncSerialUpdated ¶
SyncSerialUpdated is emitted when the sync manager's serial is updated.
func NewSyncSerialUpdated ¶
func NewSyncSerialUpdated(serial uint64) *SyncSerialUpdated
NewSyncSerialUpdated creates a new SyncSerialUpdated domain event.
type UserAuthenticated ¶
type UserAuthenticated struct {
Base
Pubkey []byte // The authenticated pubkey
AccessLevel string // The granted access level
IsFirstTime bool // Whether this is a first-time user
ConnectionID string // The connection ID
}
UserAuthenticated is emitted when a user successfully authenticates.
func NewUserAuthenticated ¶
func NewUserAuthenticated(pubkey []byte, accessLevel string, isFirstTime bool, connID string) *UserAuthenticated
NewUserAuthenticated creates a new UserAuthenticated domain event.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package subscribers provides domain event subscriber implementations.
|
Package subscribers provides domain event subscriber implementations. |