{"modulePath":"github.com/get-eventually/go-eventually","version":"v0.4.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package query\n\nPackage query provides support and utilities to handle and implement Domain Queries in your application.\n\n## Types\n\n```go\ntype Envelope[T Query] message.Envelope[T]\n```\nEnvelope represents a message containing a Domain Query, and optionally includes additional fields in the form of Metadata.\n\n```go\nfunc ToEnvelope[T Query](query T) Envelope[T]\n```\nToEnvelope is a convenience function that wraps the provided Query type into an Envelope, with no metadata attached to it.\n\n```go\ntype Handler[T Query, R any] interface {\n\tHandle(ctx context.Context, query Envelope[T]) (R, error)\n}\n```\nHandler is the interface that defines a Query Handler.\n\nHandler accepts a specific kind of Query, evaluates it and returns the desired Result.\n\n```go\ntype HandlerFunc[T Query, R any] func(ctx context.Context, query Envelope[T]) (R, error)\n```\nHandlerFunc is a functional type that implements the Handler interface. Useful for testing and stateless Handlers.\n\n```go\nfunc (f HandlerFunc[T, R]) Handle(ctx context.Context, query Envelope[T]) (R, error)\n```\nHandle implements query.Handler.\n\n```go\ntype ProcessorHandler[Q Query, R any] interface {\n\tHandler[Q, R]\n\tevent.Processor\n}\n```\nProcessorHandler is a Query Handler that can both handle domain queries, and domain events to hydrate the query model.\n\nTo be used in the Scenario.\n\n```go\ntype Query message.Message\n```\nQuery represents a Domain Query, a request for information. Queries should be phrased in the present, imperative tense, such as \"ListUsers\".\n\n```go\ntype ScenarioGiven[Q Query, R any, T ProcessorHandler[Q, R]] struct {\n\t// contains filtered or unexported fields\n}\n```\nScenarioGiven is the state of the scenario once a set of Domain Events have been provided using Given(), to represent the state of the system at the time of evaluating a Domain Event.\n\n```go\nfunc (sc ScenarioGiven[Q, R, T]) When(q Envelope[Q]) ScenarioWhen[Q, R, T]\n```\nWhen provides the Command to evaluate.\n\n```go\ntype ScenarioInit[Q Query, R any, T ProcessorHandler[Q, R]] struct{}\n```\nScenarioInit is the entrypoint of the Query Handler scenario API.\n\nA Query Handler scenario can either set the current evaluation context by using Given(), or test a \"clean-slate\" scenario by using When() directly.\n\n```go\nfunc Scenario[Q Query, R any, T ProcessorHandler[Q, R]]() ScenarioInit[Q, R, T]\n```\nScenario can be used to test the result of Domain Queries being handled by a Query Handler.\n\nQuery Handlers in Event-sourced systems return read-only data on request by means of Domain Queries. This scenario API helps you with testing the values returned by a Query Handler when handling a specific Domain Query.\n\n```go\nfunc (sc ScenarioInit[Q, R, T]) Given(events ...event.Persisted) ScenarioGiven[Q, R, T]\n```\nGiven sets the Query Handler scenario preconditions.\n\nDomain Events are used in Event-sourced systems to represent a side effect that has taken place in the system. In order to set a given state for the system to be in while testing a specific Domain Query evaluation, you should specify the Domain Events that have happened thus far.\n\nWhen you're testing Domain Queries with a clean-slate system, you should either specify no Domain Events, or skip directly to When().\n\n```go\nfunc (sc ScenarioInit[Q, R, T]) When(q Envelope[Q]) ScenarioWhen[Q, R, T]\n```\nWhen provides the Domain Query to evaluate.\n\n```go\ntype ScenarioThen[Q Query, R any, T ProcessorHandler[Q, R]] struct {\n\tScenarioWhen[Q, R, T]\n\t// contains filtered or unexported fields\n}\n```\nScenarioThen is the state of the scenario once the preconditions and expectations have been fully specified.\n\n```go\nfunc (sc ScenarioThen[Q, R, T]) AssertOn(\n\tt *testing.T,\n\thandlerFactory func(es event.Store) T,\n)\n```\nAssertOn performs the specified expectations of the scenario, using the Query Handler instance produced by the provided factory function.\n\n```go\ntype ScenarioWhen[Q Query, R any, T ProcessorHandler[Q, R]] struct {\n\tScenarioGiven[Q, R, T]\n\t// contains filtered or unexported fields\n}\n```\nScenarioWhen is the state of the scenario once the state of the system and the Domain Query to evaluate has been provided.\n\n```go\nfunc (sc ScenarioWhen[Q, R, T]) Then(result R) ScenarioThen[Q, R, T]\n```\nThen sets a positive expectation on the scenario outcome, to produce the Query Result provided in input.\n\n```go\nfunc (sc ScenarioWhen[Q, R, T]) ThenError(err error) ScenarioThen[Q, R, T]\n```\nThenError sets a negative expectation on the scenario outcome, to produce an error value that is similar to the one provided in input.\n\nError assertion happens using errors.Is(), so the error returned by the Query Handler is unwrapped until the cause error to match the provided expectation.\n\n```go\nfunc (sc ScenarioWhen[Q, R, T]) ThenFails() ScenarioThen[Q, R, T]\n```\nThenFails sets a negative expectation on the scenario outcome, to fail the Domain Query evaluation with no particular assertion on the error returned.\n\nThis is useful when the error returned is not important for the Domain Query you're trying to test.\n\n","path":"github.com/get-eventually/go-eventually/query","name":"query","synopsis":"Package query provides support and utilities to handle and implement Domain Queries in your application.","isRedistributable":true}
