Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate configkit #53

Merged
merged 53 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
788ce0d
Add `optional` package.
jmalloc Oct 6, 2024
c31b487
Add `typename` package.
jmalloc Oct 7, 2024
0bb6445
Add options to `test.Expect()` to allow it to compare optional types.
jmalloc Oct 7, 2024
07d3e47
Add `config` package.
jmalloc Oct 7, 2024
412758a
Add `runtimeconfig` package.
jmalloc Oct 7, 2024
461035c
Add `config.Identity.Validate()`.
jmalloc Oct 7, 2024
a14c951
Add `config.Identity.Normalize()`.
jmalloc Oct 7, 2024
716362f
Add `IsExhaustive` flag.
jmalloc Oct 7, 2024
2e36c2a
Added `config.Implementation`.
jmalloc Oct 7, 2024
03bb50a
Implement application validation.
jmalloc Oct 9, 2024
6a43767
Split error structs into separate files.
jmalloc Oct 9, 2024
72b1549
Add validation of required route types.
jmalloc Oct 9, 2024
6d7772c
Add `validationContext`.
jmalloc Oct 9, 2024
aaa98de
Improve error messages.
jmalloc Oct 9, 2024
67311c9
Add validation tests for integration handlers.
jmalloc Oct 9, 2024
c15ebd9
Add validation tests for process handlers.
jmalloc Oct 9, 2024
5c2cd99
Add validation tests for projection handlers.
jmalloc Oct 9, 2024
d13dd32
Add tests for `Identity()` methods.
jmalloc Oct 9, 2024
c081120
Implement route validation.
jmalloc Oct 10, 2024
9ec93ff
Add `HandlerType` enumeration.
jmalloc Oct 10, 2024
1ae5ff2
Add `IsDisabled()` and `IsExhaustive()` methods.
jmalloc Oct 10, 2024
333893f
Add `SwitchByHandlerTypeOf()`.
jmalloc Oct 10, 2024
3f6536f
Add `HandlerType.String()`.
jmalloc Oct 10, 2024
8ed7859
Interface()` method to all entities.
jmalloc Oct 10, 2024
014fbc1
Add `HandlerByName()`.
jmalloc Oct 10, 2024
b14b5d5
Add `Application.Handlers()`.
jmalloc Oct 10, 2024
494b1f6
Add `InboundRouteTypes` and `OutboundRouteTypes`.
jmalloc Oct 10, 2024
c8ef316
Add `RouteDirection`.
jmalloc Oct 10, 2024
65cc343
Change `MessageTypes()` to return a map.
jmalloc Oct 10, 2024
514466c
Add `RouteDirection.Is()`.
jmalloc Oct 10, 2024
5529443
Add `filter` parameter to `MessageTypes()`.
jmalloc Oct 10, 2024
f846ce7
Rename `Is()` to `Has()`.
jmalloc Oct 10, 2024
07aea52
Add functions that return all enum values.
jmalloc Oct 10, 2024
ddf535b
Implement filterable route sets.
jmalloc Oct 11, 2024
7fd3d61
Rename `Routes()` to `RouteSet()`.
jmalloc Oct 11, 2024
b6783e5
Add `RouteSet.HasMessageType()`.
jmalloc Oct 11, 2024
7b06d73
Add `Fidelity`.
jmalloc Oct 14, 2024
a6e58e7
Move `Identity` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
840bdea
Move `Application` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
2988349
Move `Aggregate` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
8074de6
Move `Integration` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
c51571c
Move `Process` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
869e2ad
Move `Projection` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
205a0bf
Move `Route` properties into an `AsConfigured` field.
jmalloc Oct 14, 2024
aa6f90f
Make name and key elements of a identity optional.
jmalloc Oct 14, 2024
af4f2bb
Use more intuitive names for route set filters.
jmalloc Oct 14, 2024
73788ec
Use `enum` package to implement `HandlerType`.
jmalloc Oct 15, 2024
28a4472
Fix filenames.
jmalloc Oct 15, 2024
59b39f9
Use `enum` package to implement `RouteType`.
jmalloc Oct 15, 2024
09710f3
Add tests for `IsDisabled()` methods.
jmalloc Oct 15, 2024
f25ad7b
Abstract validation tests.
jmalloc Oct 15, 2024
7fff15c
Implement `WithImplementations()` option.
jmalloc Oct 15, 2024
0479923
Rename `WithImplementations()` to `WithRuntimeValues()`.
jmalloc Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions config/aggregate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package config

import (
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/optional"
"github.com/dogmatiq/enginekit/protobuf/identitypb"
)

// AggregateAsConfigured contains the raw unvalidated properties of an
// [Aggregate].
type AggregateAsConfigured struct {
// Source describes the type and value that produced the configuration, if
// available.
Source optional.Optional[Value[dogma.AggregateMessageHandler]]

// Identities is the list of identities configured for the handler.
Identities []Identity

// Routes is the list of routes configured on the handler.
Routes []Route

// IsDisabled is true if the handler was disabled via the configurer, if
// known.
IsDisabled optional.Optional[bool]

// Fidelity describes the configuration's accuracy in comparison to the
// actual configuration that would be used at runtime.
Fidelity Fidelity
}

// Aggregate represents the (potentially invalid) configuration of a
// [dogma.AggregateMessageHandler] implementation.
type Aggregate struct {
AsConfigured AggregateAsConfigured
}

func (h *Aggregate) String() string {
return renderEntity("aggregate", h, h.AsConfigured.Source)
}

// Identity returns the entity's identity.
//
// It panics if no single valid identity is configured.
func (h *Aggregate) Identity() *identitypb.Identity {
return finalizeIdentity(newFinalizeContext(h), h)
}

// Fidelity returns information about how well the configuration represents
// the actual configuration that would be used at runtime.
func (h *Aggregate) Fidelity() Fidelity {
return h.AsConfigured.Fidelity
}

// HandlerType returns [HandlerType] of the handler.
func (h *Aggregate) HandlerType() HandlerType {
return AggregateHandlerType
}

// RouteSet returns the routes configured for the handler.
//
// It panics if the routes are incomplete or invalid.
func (h *Aggregate) RouteSet() RouteSet {
return finalizeRouteSet(newFinalizeContext(h), h)
}

// IsDisabled returns true if the handler was disabled via the configurer.
func (h *Aggregate) IsDisabled() bool {
return h.AsConfigured.IsDisabled.Get()
}

// Interface returns the [dogma.AggregateMessageHandler] instance that the
// configuration represents, or panics if it is not available.
func (h *Aggregate) Interface() dogma.AggregateMessageHandler {
return h.AsConfigured.Source.Get().Value.Get()
}

func (h *Aggregate) normalize(ctx *normalizeContext) Component {
h.AsConfigured.Fidelity, h.AsConfigured.Source = normalizeValue(ctx, h.AsConfigured.Fidelity, h.AsConfigured.Source)
h.AsConfigured.Identities = normalizeIdentities(ctx, h)
h.AsConfigured.Routes = normalizeRoutes(ctx, h)
return h
}

func (h *Aggregate) identitiesAsConfigured() []Identity {
return h.AsConfigured.Identities
}

func (h *Aggregate) routesAsConfigured() []Route {
return h.AsConfigured.Routes
}
Loading