mirror of
https://github.com/bitwarden/server
synced 2026-01-14 22:43:19 +00:00
We want to reduce the amount of business critical test data in the company. One way of doing that is to generate test data on demand prior to client side testing. Clients will request a scene to be set up with a JSON body set of options, specific to a given scene. Successful seed requests will be responded to with a mangleMap which maps magic strings present in the request to the mangled, non-colliding versions inserted into the database. This way, the server is solely responsible for understanding uniqueness requirements in the database. scenes also are able to return custom data, depending on the scene. For example, user creation would benefit from a return value of the userId for further test setup on the client side. Clients will indicate they are running tests by including a unique header, x-play-id which specifies a unique testing context. The server uses this PlayId as the seed for any mangling that occurs. This allows the client to decide it will reuse a given PlayId if the test context builds on top of previously executed tests. When a given context is no longer needed, the API user will delete all test data associated with the PlayId by calling a delete endpoint. --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
61 lines
2.7 KiB
C#
61 lines
2.7 KiB
C#
namespace Bit.Seeder;
|
|
|
|
/// <summary>
|
|
/// Base interface for query operations in the seeding system. The base interface should not be used directly, rather use `IQuery<TRequest, TResult>`.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Queries are synchronous, read-only operations that retrieve data from the seeding context.
|
|
/// Unlike scenes which create data, queries fetch existing data based on request parameters.
|
|
/// They follow a type-safe pattern using generics to ensure proper request/response handling
|
|
/// while maintaining a common non-generic interface for dynamic invocation.
|
|
/// </remarks>
|
|
public interface IQuery
|
|
{
|
|
/// <summary>
|
|
/// Gets the type of request this query expects.
|
|
/// </summary>
|
|
/// <returns>The request type that this query can process.</returns>
|
|
Type GetRequestType();
|
|
|
|
/// <summary>
|
|
/// Executes the query based on the provided request object.
|
|
/// </summary>
|
|
/// <param name="request">The request object containing parameters for the query operation.</param>
|
|
/// <returns>The query result data as an object.</returns>
|
|
object Execute(object request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generic query interface for synchronous, read-only operations with specific request and result types.
|
|
/// </summary>
|
|
/// <typeparam name="TRequest">The type of request object this query accepts.</typeparam>
|
|
/// <typeparam name="TResult">The type of data this query returns.</typeparam>
|
|
/// <remarks>
|
|
/// Use this interface when you need to retrieve existing data from the seeding context based on
|
|
/// specific request parameters. Queries are synchronous and do not modify data - they only read
|
|
/// and return information. The explicit interface implementations allow dynamic invocation while
|
|
/// maintaining type safety in the implementation.
|
|
/// </remarks>
|
|
public interface IQuery<TRequest, TResult> : IQuery where TRequest : class where TResult : class
|
|
{
|
|
/// <summary>
|
|
/// Executes the query based on the provided strongly-typed request and returns typed result data.
|
|
/// </summary>
|
|
/// <param name="request">The request object containing parameters for the query operation.</param>
|
|
/// <returns>The typed query result data.</returns>
|
|
TResult Execute(TRequest request);
|
|
|
|
/// <summary>
|
|
/// Gets the request type for this query.
|
|
/// </summary>
|
|
/// <returns>The type of TRequest.</returns>
|
|
Type IQuery.GetRequestType() => typeof(TRequest);
|
|
|
|
/// <summary>
|
|
/// Adapts the non-generic Execute to the strongly-typed version.
|
|
/// </summary>
|
|
/// <param name="request">The request object to cast and process.</param>
|
|
/// <returns>The typed result cast to object.</returns>
|
|
object IQuery.Execute(object request) => Execute((TRequest)request);
|
|
}
|