diff --git a/enginetest/internal/action/behavior.go b/enginetest/internal/action/behavior.go index 59b3666..f0542ff 100644 --- a/enginetest/internal/action/behavior.go +++ b/enginetest/internal/action/behavior.go @@ -28,7 +28,7 @@ func Fail(message string) []*Action { } } -func (x *Action_Fail) do(s Scope) error { +func (x *Action_Fail) do(Scope) error { return errors.New(x.Fail) } @@ -58,7 +58,7 @@ func ExecuteCommand(c dogma.Command) []*Action { } func (x *Action_ExecuteCommand) do(s Scope) error { - s.(executor).ExecuteCommand(fromAny(x.ExecuteCommand)) + s.(executor).ExecuteCommand(fromAny[dogma.Command](x.ExecuteCommand)) return nil } @@ -73,7 +73,7 @@ func RecordEvent(e dogma.Message) []*Action { } func (x *Action_RecordEvent) do(s Scope) error { - s.(recorder).RecordEvent(fromAny(x.RecordEvent)) + s.(recorder).RecordEvent(fromAny[dogma.Event](x.RecordEvent)) return nil } @@ -94,7 +94,7 @@ func ScheduleTimeout(t dogma.Timeout, at time.Time) []*Action { func (x *Action_ScheduleTimeout) do(s Scope) error { s.(scheduler).ScheduleTimeout( - fromAny(x.ScheduleTimeout.Timeout), + fromAny[dogma.Timeout](x.ScheduleTimeout.Timeout), x.ScheduleTimeout.At.AsTime(), ) return nil @@ -137,10 +137,10 @@ func toAny(m dogma.Message) *anypb.Any { return x } -func fromAny(m *anypb.Any) dogma.Message { +func fromAny[T dogma.Message](m *anypb.Any) T { x, err := m.UnmarshalNew() if err != nil { panic(err) } - return x.(dogma.Message) + return x.(T) } diff --git a/enginetest/internal/action/doc.go b/enginetest/internal/action/doc.go new file mode 100644 index 0000000..1a58c97 --- /dev/null +++ b/enginetest/internal/action/doc.go @@ -0,0 +1,3 @@ +// Package action provides a mechanism for triggering arbitrary actions within +// handlers by encoding the actions to perform within Dogma messages. +package action diff --git a/enginetest/internal/testapp/integration.go b/enginetest/internal/testapp/integration.go index 4db178c..9f05d2c 100644 --- a/enginetest/internal/testapp/integration.go +++ b/enginetest/internal/testapp/integration.go @@ -65,7 +65,7 @@ func (x *IntegrationCommandA) MessageDescription() string { } // Validate returns an error if the message is invalid. -func (x *IntegrationCommandA) Validate() error { +func (x *IntegrationCommandA) Validate(dogma.CommandValidationScope) error { if x.IsInvalid { return ErrInvalidIntegrationMessage } @@ -78,7 +78,7 @@ func (x *IntegrationCommandB) MessageDescription() string { } // Validate returns an error if the message is invalid. -func (x *IntegrationCommandB) Validate() error { +func (x *IntegrationCommandB) Validate(dogma.CommandValidationScope) error { if x.IsInvalid { return ErrInvalidIntegrationMessage } @@ -91,7 +91,7 @@ func (x *IntegrationEventA) MessageDescription() string { } // Validate returns an error if the message is invalid. -func (x *IntegrationEventA) Validate() error { +func (x *IntegrationEventA) Validate(dogma.EventValidationScope) error { return nil } @@ -101,6 +101,6 @@ func (x *IntegrationEventB) MessageDescription() string { } // Validate returns an error if the message is invalid. -func (x *IntegrationEventB) Validate() error { +func (x *IntegrationEventB) Validate(dogma.EventValidationScope) error { return nil } diff --git a/enginetest/stubs/message.go b/enginetest/stubs/message.go index c4343ea..a34202a 100644 --- a/enginetest/stubs/message.go +++ b/enginetest/stubs/message.go @@ -3,6 +3,8 @@ package stubs import ( "errors" "fmt" + + "github.com/dogmatiq/dogma" ) // CommandStub is a test implementation of [dogma.Command]. @@ -26,7 +28,7 @@ func (s CommandStub[T]) MessageDescription() string { } // Validate returns a non-nil error if c.Invalid is not empty. -func (s CommandStub[T]) Validate() error { +func (s CommandStub[T]) Validate(dogma.CommandValidationScope) error { if s.ValidationError != "" { return errors.New(s.ValidationError) } @@ -54,7 +56,7 @@ func (s EventStub[T]) MessageDescription() string { } // Validate returns a non-nil error if c.Invalid is not empty. -func (s EventStub[T]) Validate() error { +func (s EventStub[T]) Validate(dogma.EventValidationScope) error { if s.ValidationError != "" { return errors.New(s.ValidationError) } @@ -82,7 +84,7 @@ func (s TimeoutStub[T]) MessageDescription() string { } // Validate returns a non-nil error if c.Invalid is not empty. -func (s TimeoutStub[T]) Validate() error { +func (s TimeoutStub[T]) Validate(dogma.TimeoutValidationScope) error { if s.ValidationError != "" { return errors.New(s.ValidationError) } diff --git a/go.mod b/go.mod index fa9584f..e1b37bb 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( github.com/dogmatiq/dapper v0.6.0 - github.com/dogmatiq/dogma v0.14.3 + github.com/dogmatiq/dogma v0.15.0 github.com/dogmatiq/primo v0.3.1 github.com/google/go-cmp v0.6.0 google.golang.org/grpc v1.67.1 diff --git a/go.sum b/go.sum index e022c7c..aa348a5 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ github.com/dogmatiq/dapper v0.6.0 h1:hnWUsjnt3nUiC9hmkPvuxrnMd7fYNz1i+/GS3gOx0Xs= github.com/dogmatiq/dapper v0.6.0/go.mod h1:ubRHWzt73s0MsPpGhWvnfW/Z/1YPnrkCsQv6CUOZVEw= -github.com/dogmatiq/dogma v0.14.3 h1:qwZqU1yqp80toUJcJBdFxLlh6xvlFd7jb7rycmriRUo= -github.com/dogmatiq/dogma v0.14.3/go.mod h1:9lyVA+6V2+E/exV0IrBOrkUiyFwIATEhv+b0vnB2umQ= +github.com/dogmatiq/dogma v0.14.4-0.20240926234834-3c0cc27a2ca1 h1:SKhtRnDs7CC3ZNMux7lYCxCFz5ZhmeXjvo7/uMNISLo= +github.com/dogmatiq/dogma v0.14.4-0.20240926234834-3c0cc27a2ca1/go.mod h1:9lyVA+6V2+E/exV0IrBOrkUiyFwIATEhv+b0vnB2umQ= +github.com/dogmatiq/dogma v0.15.0 h1:aXOTd2K4wLvlwHc1D9OsFREp0BusNJ9o9KssxURftmg= +github.com/dogmatiq/dogma v0.15.0/go.mod h1:TF6xisRxQ2RE3JQwFr6MCI4nWLKQQp7KRWXVHOq9K0k= github.com/dogmatiq/jumble v0.1.0 h1:Cb3ExfxY+AoUP4G9/sOwoOdYX8o+kOLK8+dhXAry+QA= github.com/dogmatiq/jumble v0.1.0/go.mod h1:FCGV2ImXu8zvThxhd4QLstiEdu74vbIVw9bFJSBcKr4= github.com/dogmatiq/primo v0.3.1 h1:JSqiCh1ma9CbIVzPf8k1vhzQ2Zn/d/WupzElDoiYZw0= diff --git a/protobuf/configpb/config.pb.go b/protobuf/configpb/config.pb.go index 74b4caf..72b3166 100644 --- a/protobuf/configpb/config.pb.go +++ b/protobuf/configpb/config.pb.go @@ -146,6 +146,9 @@ type Application struct { GoType string `protobuf:"bytes,2,opt,name=go_type,json=goType,proto3" json:"go_type,omitempty"` // Handlers is the set of handlers within the application. Handlers []*Handler `protobuf:"bytes,3,rep,name=handlers,proto3" json:"handlers,omitempty"` + // MessageKinds is a map of each message type's fully-qualified Go type to its + // the kind of message it implemented by that type. + Messages map[string]MessageKind `protobuf:"bytes,4,rep,name=messages,proto3" json:"messages,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=dogma.protobuf.MessageKind"` } func (x *Application) Reset() { @@ -201,6 +204,13 @@ func (x *Application) GetHandlers() []*Handler { return nil } +func (x *Application) GetMessages() map[string]MessageKind { + if x != nil { + return x.Messages + } + return nil +} + // Handler is a message handler within an application. type Handler struct { state protoimpl.MessageState @@ -214,18 +224,12 @@ type Handler struct { GoType string `protobuf:"bytes,2,opt,name=go_type,json=goType,proto3" json:"go_type,omitempty"` // Type is the handler's type. Type HandlerType `protobuf:"varint,3,opt,name=type,proto3,enum=dogma.protobuf.HandlerType" json:"type,omitempty"` - // ProducedMessages is the set of messages produced by this handler. - // - // The keys are the fully-qualified names of the message's Go type and the - // value is the kind of message implemented by that type. - ProducedMessages map[string]MessageKind `protobuf:"bytes,4,rep,name=produced_messages,json=producedMessages,proto3" json:"produced_messages,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=dogma.protobuf.MessageKind"` - // ConsumedMessages is the set of messages consumed by this handler. + // messages is the set of messages produced and consumed by this handler. // - // The keys are the fully-qualified names of the message's Go type and the - // value is the kind of message implemented by that type. - ConsumedMessages map[string]MessageKind `protobuf:"bytes,5,rep,name=consumed_messages,json=consumedMessages,proto3" json:"consumed_messages,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=dogma.protobuf.MessageKind"` + // The keys are the fully-qualified names of the message's Go type. + Messages map[string]*MessageUsage `protobuf:"bytes,4,rep,name=messages,proto3" json:"messages,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // IsDisabled indicates whether the handler is disabled. - IsDisabled bool `protobuf:"varint,6,opt,name=is_disabled,json=isDisabled,proto3" json:"is_disabled,omitempty"` + IsDisabled bool `protobuf:"varint,5,opt,name=is_disabled,json=isDisabled,proto3" json:"is_disabled,omitempty"` } func (x *Handler) Reset() { @@ -281,23 +285,73 @@ func (x *Handler) GetType() HandlerType { return HandlerType_UNKNOWN_HANDLER_TYPE } -func (x *Handler) GetProducedMessages() map[string]MessageKind { +func (x *Handler) GetMessages() map[string]*MessageUsage { if x != nil { - return x.ProducedMessages + return x.Messages } return nil } -func (x *Handler) GetConsumedMessages() map[string]MessageKind { +func (x *Handler) GetIsDisabled() bool { if x != nil { - return x.ConsumedMessages + return x.IsDisabled } - return nil + return false } -func (x *Handler) GetIsDisabled() bool { +type MessageUsage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // IsProduced indicates whether the message is produced by the handler. + IsProduced bool `protobuf:"varint,2,opt,name=is_produced,json=isProduced,proto3" json:"is_produced,omitempty"` + // IsConsumed indicates whether the message is consumed by the handler. + IsConsumed bool `protobuf:"varint,3,opt,name=is_consumed,json=isConsumed,proto3" json:"is_consumed,omitempty"` +} + +func (x *MessageUsage) Reset() { + *x = MessageUsage{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MessageUsage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MessageUsage) ProtoMessage() {} + +func (x *MessageUsage) ProtoReflect() protoreflect.Message { + mi := &file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MessageUsage.ProtoReflect.Descriptor instead. +func (*MessageUsage) Descriptor() ([]byte, []int) { + return file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_rawDescGZIP(), []int{2} +} + +func (x *MessageUsage) GetIsProduced() bool { if x != nil { - return x.IsDisabled + return x.IsProduced + } + return false +} + +func (x *MessageUsage) GetIsConsumed() bool { + if x != nil { + return x.IsConsumed } return false } @@ -314,7 +368,7 @@ var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_rawDesc = 0x74, 0x69, 0x71, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x70, 0x62, 0x2f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x91, 0x01, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0xb2, 0x02, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x34, 0x0a, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x08, 0x69, 0x64, @@ -323,56 +377,58 @@ var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_rawDesc = 0x33, 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x52, 0x08, 0x68, 0x61, 0x6e, 0x64, - 0x6c, 0x65, 0x72, 0x73, 0x22, 0xa6, 0x04, 0x0a, 0x07, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, - 0x12, 0x34, 0x0a, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x08, 0x69, 0x64, - 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x67, 0x6f, 0x5f, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x6f, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x2f, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, - 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, - 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, - 0x12, 0x5a, 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x64, 0x6f, - 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, 0x61, 0x6e, - 0x64, 0x6c, 0x65, 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x64, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x10, 0x70, 0x72, 0x6f, 0x64, - 0x75, 0x63, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x5a, 0x0a, 0x11, - 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, - 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x10, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x64, - 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, - 0x73, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x1a, 0x60, 0x0a, 0x15, 0x50, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4b, 0x69, 0x6e, 0x64, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x60, 0x0a, 0x15, 0x43, - 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4b, 0x69, - 0x6e, 0x64, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x4c, 0x0a, - 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x18, 0x0a, 0x14, - 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x5f, - 0x4b, 0x49, 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, - 0x44, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x10, 0x02, 0x12, 0x0b, - 0x0a, 0x07, 0x54, 0x49, 0x4d, 0x45, 0x4f, 0x55, 0x54, 0x10, 0x03, 0x2a, 0x64, 0x0a, 0x0b, 0x48, - 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x4e, - 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x48, 0x41, 0x4e, 0x44, 0x4c, 0x45, 0x52, 0x5f, 0x54, 0x59, - 0x50, 0x45, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, - 0x45, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x4f, 0x43, 0x45, 0x53, 0x53, 0x10, 0x02, - 0x12, 0x0f, 0x0a, 0x0b, 0x49, 0x4e, 0x54, 0x45, 0x47, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, - 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x50, 0x52, 0x4f, 0x4a, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x10, - 0x04, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x74, 0x69, 0x71, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x6b, - 0x69, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x65, 0x72, 0x73, 0x12, 0x45, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, + 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x1a, 0x58, 0x0a, 0x0d, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x31, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, + 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xc8, 0x02, 0x0a, 0x07, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, + 0x72, 0x12, 0x34, 0x0a, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x08, 0x69, + 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x67, 0x6f, 0x5f, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x6f, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x2f, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, + 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x12, 0x41, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x2e, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x64, 0x69, 0x73, 0x61, 0x62, + 0x6c, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x44, 0x69, 0x73, + 0x61, 0x62, 0x6c, 0x65, 0x64, 0x1a, 0x59, 0x0a, 0x0d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x32, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, + 0x22, 0x50, 0x0a, 0x0c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, + 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, + 0x65, 0x64, 0x2a, 0x4c, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4b, 0x69, 0x6e, + 0x64, 0x12, 0x18, 0x0a, 0x14, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x4d, 0x45, 0x53, + 0x53, 0x41, 0x47, 0x45, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, + 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x56, 0x45, 0x4e, + 0x54, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x54, 0x49, 0x4d, 0x45, 0x4f, 0x55, 0x54, 0x10, 0x03, + 0x2a, 0x64, 0x0a, 0x0b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x18, 0x0a, 0x14, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x48, 0x41, 0x4e, 0x44, 0x4c, + 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x41, 0x47, 0x47, + 0x52, 0x45, 0x47, 0x41, 0x54, 0x45, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x4f, 0x43, + 0x45, 0x53, 0x53, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x49, 0x4e, 0x54, 0x45, 0x47, 0x52, 0x41, + 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x50, 0x52, 0x4f, 0x4a, 0x45, 0x43, + 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x04, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x67, 0x6d, 0x61, 0x74, 0x69, 0x71, 0x2f, 0x65, 0x6e, + 0x67, 0x69, 0x6e, 0x65, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -388,25 +444,26 @@ func file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_rawDescGZ } var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_goTypes = []any{ (MessageKind)(0), // 0: dogma.protobuf.MessageKind (HandlerType)(0), // 1: dogma.protobuf.HandlerType (*Application)(nil), // 2: dogma.protobuf.Application (*Handler)(nil), // 3: dogma.protobuf.Handler - nil, // 4: dogma.protobuf.Handler.ProducedMessagesEntry - nil, // 5: dogma.protobuf.Handler.ConsumedMessagesEntry - (*identitypb.Identity)(nil), // 6: dogma.protobuf.Identity + (*MessageUsage)(nil), // 4: dogma.protobuf.MessageUsage + nil, // 5: dogma.protobuf.Application.MessagesEntry + nil, // 6: dogma.protobuf.Handler.MessagesEntry + (*identitypb.Identity)(nil), // 7: dogma.protobuf.Identity } var file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_depIdxs = []int32{ - 6, // 0: dogma.protobuf.Application.identity:type_name -> dogma.protobuf.Identity + 7, // 0: dogma.protobuf.Application.identity:type_name -> dogma.protobuf.Identity 3, // 1: dogma.protobuf.Application.handlers:type_name -> dogma.protobuf.Handler - 6, // 2: dogma.protobuf.Handler.identity:type_name -> dogma.protobuf.Identity - 1, // 3: dogma.protobuf.Handler.type:type_name -> dogma.protobuf.HandlerType - 4, // 4: dogma.protobuf.Handler.produced_messages:type_name -> dogma.protobuf.Handler.ProducedMessagesEntry - 5, // 5: dogma.protobuf.Handler.consumed_messages:type_name -> dogma.protobuf.Handler.ConsumedMessagesEntry - 0, // 6: dogma.protobuf.Handler.ProducedMessagesEntry.value:type_name -> dogma.protobuf.MessageKind - 0, // 7: dogma.protobuf.Handler.ConsumedMessagesEntry.value:type_name -> dogma.protobuf.MessageKind + 5, // 2: dogma.protobuf.Application.messages:type_name -> dogma.protobuf.Application.MessagesEntry + 7, // 3: dogma.protobuf.Handler.identity:type_name -> dogma.protobuf.Identity + 1, // 4: dogma.protobuf.Handler.type:type_name -> dogma.protobuf.HandlerType + 6, // 5: dogma.protobuf.Handler.messages:type_name -> dogma.protobuf.Handler.MessagesEntry + 0, // 6: dogma.protobuf.Application.MessagesEntry.value:type_name -> dogma.protobuf.MessageKind + 4, // 7: dogma.protobuf.Handler.MessagesEntry.value:type_name -> dogma.protobuf.MessageUsage 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name @@ -444,6 +501,18 @@ func file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_init() { return nil } } + file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*MessageUsage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -451,7 +520,7 @@ func file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_github_com_dogmatiq_enginekit_protobuf_configpb_config_proto_rawDesc, NumEnums: 2, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/protobuf/configpb/config.proto b/protobuf/configpb/config.proto index c0cfd44..a78e12c 100644 --- a/protobuf/configpb/config.proto +++ b/protobuf/configpb/config.proto @@ -36,6 +36,10 @@ message Application { // Handlers is the set of handlers within the application. repeated Handler handlers = 3; + + // MessageKinds is a map of each message type's fully-qualified Go type to its + // the kind of message it implemented by that type. + map messages = 4; } // Handler is a message handler within an application. @@ -50,18 +54,19 @@ message Handler { // Type is the handler's type. HandlerType type = 3; - // ProducedMessages is the set of messages produced by this handler. - // - // The keys are the fully-qualified names of the message's Go type and the - // value is the kind of message implemented by that type. - map produced_messages = 4; - - // ConsumedMessages is the set of messages consumed by this handler. + // messages is the set of messages produced and consumed by this handler. // - // The keys are the fully-qualified names of the message's Go type and the - // value is the kind of message implemented by that type. - map consumed_messages = 5; + // The keys are the fully-qualified names of the message's Go type. + map messages = 4; // IsDisabled indicates whether the handler is disabled. - bool is_disabled = 6; + bool is_disabled = 5; +} + +message MessageUsage { + // IsProduced indicates whether the message is produced by the handler. + bool is_produced = 2; + + // IsConsumed indicates whether the message is consumed by the handler. + bool is_consumed = 3; } diff --git a/protobuf/configpb/config_primo.pb.go b/protobuf/configpb/config_primo.pb.go index 2af733e..b199e6f 100644 --- a/protobuf/configpb/config_primo.pb.go +++ b/protobuf/configpb/config_primo.pb.go @@ -29,6 +29,7 @@ func (b *ApplicationBuilder) From(x *Application) *ApplicationBuilder { b.prototype.Identity = x.Identity b.prototype.GoType = x.GoType b.prototype.Handlers = x.Handlers + b.prototype.Messages = x.Messages return b } @@ -41,6 +42,7 @@ func (b *ApplicationBuilder) Build() *Application { Identity: b.prototype.Identity, GoType: b.prototype.GoType, Handlers: b.prototype.Handlers, + Messages: b.prototype.Messages, } } @@ -65,6 +67,13 @@ func (b *ApplicationBuilder) WithHandlers(v []*Handler) *ApplicationBuilder { return b } +// WithMessages configures the builder to set the Messages field to v, +// then returns b. +func (b *ApplicationBuilder) WithMessages(v map[string]MessageKind) *ApplicationBuilder { + b.prototype.Messages = v + return b +} + type HandlerBuilder struct { prototype Handler } @@ -83,8 +92,7 @@ func (b *HandlerBuilder) From(x *Handler) *HandlerBuilder { b.prototype.Identity = x.Identity b.prototype.GoType = x.GoType b.prototype.Type = x.Type - b.prototype.ProducedMessages = x.ProducedMessages - b.prototype.ConsumedMessages = x.ConsumedMessages + b.prototype.Messages = x.Messages b.prototype.IsDisabled = x.IsDisabled return b } @@ -95,12 +103,11 @@ func (b *HandlerBuilder) From(x *Handler) *HandlerBuilder { // not modify previously constructed messages. func (b *HandlerBuilder) Build() *Handler { return &Handler{ - Identity: b.prototype.Identity, - GoType: b.prototype.GoType, - Type: b.prototype.Type, - ProducedMessages: b.prototype.ProducedMessages, - ConsumedMessages: b.prototype.ConsumedMessages, - IsDisabled: b.prototype.IsDisabled, + Identity: b.prototype.Identity, + GoType: b.prototype.GoType, + Type: b.prototype.Type, + Messages: b.prototype.Messages, + IsDisabled: b.prototype.IsDisabled, } } @@ -125,24 +132,62 @@ func (b *HandlerBuilder) WithType(v HandlerType) *HandlerBuilder { return b } -// WithProducedMessages configures the builder to set the ProducedMessages field to v, +// WithMessages configures the builder to set the Messages field to v, // then returns b. -func (b *HandlerBuilder) WithProducedMessages(v map[string]MessageKind) *HandlerBuilder { - b.prototype.ProducedMessages = v +func (b *HandlerBuilder) WithMessages(v map[string]*MessageUsage) *HandlerBuilder { + b.prototype.Messages = v return b } -// WithConsumedMessages configures the builder to set the ConsumedMessages field to v, +// WithIsDisabled configures the builder to set the IsDisabled field to v, // then returns b. -func (b *HandlerBuilder) WithConsumedMessages(v map[string]MessageKind) *HandlerBuilder { - b.prototype.ConsumedMessages = v +func (b *HandlerBuilder) WithIsDisabled(v bool) *HandlerBuilder { + b.prototype.IsDisabled = v return b } -// WithIsDisabled configures the builder to set the IsDisabled field to v, +type MessageUsageBuilder struct { + prototype MessageUsage +} + +// NewMessageUsageBuilder returns a builder that constructs [MessageUsage] messages. +func NewMessageUsageBuilder() *MessageUsageBuilder { + return &MessageUsageBuilder{} +} + +// From configures the builder to use x as the prototype for new messages, // then returns b. -func (b *HandlerBuilder) WithIsDisabled(v bool) *HandlerBuilder { - b.prototype.IsDisabled = v +// +// It performs a shallow copy of x, such that any changes made via the builder +// do not modify x. It does not make a copy of the field values themselves. +func (b *MessageUsageBuilder) From(x *MessageUsage) *MessageUsageBuilder { + b.prototype.IsProduced = x.IsProduced + b.prototype.IsConsumed = x.IsConsumed + return b +} + +// Build returns a new [MessageUsage] containing the values configured via the builder. +// +// Each call returns a new message, such that future changes to the builder do +// not modify previously constructed messages. +func (b *MessageUsageBuilder) Build() *MessageUsage { + return &MessageUsage{ + IsProduced: b.prototype.IsProduced, + IsConsumed: b.prototype.IsConsumed, + } +} + +// WithIsProduced configures the builder to set the IsProduced field to v, +// then returns b. +func (b *MessageUsageBuilder) WithIsProduced(v bool) *MessageUsageBuilder { + b.prototype.IsProduced = v + return b +} + +// WithIsConsumed configures the builder to set the IsConsumed field to v, +// then returns b. +func (b *MessageUsageBuilder) WithIsConsumed(v bool) *MessageUsageBuilder { + b.prototype.IsConsumed = v return b } @@ -302,6 +347,11 @@ func (x *Application) SetHandlers(v []*Handler) { x.Handlers = v } +// SetMessages sets the x.Messages field to v, then returns x. +func (x *Application) SetMessages(v map[string]MessageKind) { + x.Messages = v +} + // SetIdentity sets the x.Identity field to v, then returns x. func (x *Handler) SetIdentity(v *identitypb.Identity) { x.Identity = v @@ -317,17 +367,22 @@ func (x *Handler) SetType(v HandlerType) { x.Type = v } -// SetProducedMessages sets the x.ProducedMessages field to v, then returns x. -func (x *Handler) SetProducedMessages(v map[string]MessageKind) { - x.ProducedMessages = v -} - -// SetConsumedMessages sets the x.ConsumedMessages field to v, then returns x. -func (x *Handler) SetConsumedMessages(v map[string]MessageKind) { - x.ConsumedMessages = v +// SetMessages sets the x.Messages field to v, then returns x. +func (x *Handler) SetMessages(v map[string]*MessageUsage) { + x.Messages = v } // SetIsDisabled sets the x.IsDisabled field to v, then returns x. func (x *Handler) SetIsDisabled(v bool) { x.IsDisabled = v } + +// SetIsProduced sets the x.IsProduced field to v, then returns x. +func (x *MessageUsage) SetIsProduced(v bool) { + x.IsProduced = v +} + +// SetIsConsumed sets the x.IsConsumed field to v, then returns x. +func (x *MessageUsage) SetIsConsumed(v bool) { + x.IsConsumed = v +}