Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit b55d677

Browse files
refactoring before getting down to the nitty gritty
1 parent 49ad184 commit b55d677

15 files changed

Lines changed: 47 additions & 36 deletions

src/SqlStreamStore.HAL/AllStreamOptionsMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private static Action<IApplicationBuilder> ConfigureOptions(IResource resource)
3434

3535
private static MidFunc Options(IResource resource) => (context, next) =>
3636
{
37-
context.SetStandardCorsHeaders(resource.Options);
37+
context.SetStandardCorsHeaders(resource.Allowed);
3838

3939
return Task.CompletedTask;
4040
};

src/SqlStreamStore.HAL/AppendStreamMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static MidFunc AppendStream(StreamResource stream) => async (context, ne
2525
{
2626
var options = await AppendStreamOperation.Create(context.Request, context.RequestAborted);
2727

28-
var response = await stream.AppendMessages(options, context.RequestAborted);
28+
var response = await stream.Post(options, context.RequestAborted);
2929

3030
await context.WriteHalResponse(response);
3131
};

src/SqlStreamStore.HAL/HttpContextExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public static void SetStandardCorsHeaders(this HttpContext context, params HttpM
4646
{
4747
if(allowedMethods?.Length > 0)
4848
{
49-
context.Response.Headers.Append("Access-Control-Allow-Methods",
50-
allowedMethods.Select(_ => _.Method).ToArray());
49+
context.Response.Headers.Append(
50+
"Access-Control-Allow-Methods",
51+
Array.ConvertAll(allowedMethods, _ => _.Method));
5152
}
5253

5354
context.Response.Headers.Append(

src/SqlStreamStore.HAL/ReadAllStreamMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static MidFunc GetStream(AllStreamResource allStream) => async (context,
3232
{
3333
var options = new ReadAllStreamOperation(context.Request);
3434

35-
var response = await allStream.GetPage(options, context.RequestAborted);
35+
var response = await allStream.Get(options, context.RequestAborted);
3636

3737
using(new OptionalHeadRequestWrapper(context))
3838
{
@@ -42,7 +42,7 @@ private static MidFunc GetStream(AllStreamResource allStream) => async (context,
4242

4343
private static MidFunc GetStreamMessage(AllStreamMessageResource allStreamMessages) => async (context, next) =>
4444
{
45-
var response = await allStreamMessages.GetMessage(
45+
var response = await allStreamMessages.Get(
4646
new ReadAllStreamMessageOperation(context.Request),
4747
context.RequestAborted);
4848

src/SqlStreamStore.HAL/ReadStreamMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static MidFunc GetStream(StreamResource streams) => async (context, next
3131
{
3232
var options = new ReadStreamOperation(context.Request);
3333

34-
var response = await streams.GetPage(options, context.RequestAborted);
34+
var response = await streams.Get(options, context.RequestAborted);
3535

3636
using(new OptionalHeadRequestWrapper(context))
3737
{
@@ -43,7 +43,7 @@ private static MidFunc GetStreamMessage(StreamMessageResource streamMessages) =>
4343
{
4444
var options = new ReadStreamMessageByStreamVersionOperation(context.Request);
4545

46-
var response = await streamMessages.GetMessage(options, context.RequestAborted);
46+
var response = await streamMessages.Get(options, context.RequestAborted);
4747

4848
using(new OptionalHeadRequestWrapper(context))
4949
{

src/SqlStreamStore.HAL/Resources/AllStreamMessageResource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class AllStreamMessageResource : IResource
1111
{
1212
private readonly IStreamStore _streamStore;
1313

14-
public HttpMethod[] Options { get; } =
14+
public HttpMethod[] Allowed { get; } =
1515
{
1616
HttpMethod.Get,
1717
HttpMethod.Head,
@@ -25,7 +25,7 @@ public AllStreamMessageResource(IStreamStore streamStore)
2525
_streamStore = streamStore;
2626
}
2727

28-
public async Task<Response> GetMessage(
28+
public async Task<Response> Get(
2929
ReadAllStreamMessageOperation operation,
3030
CancellationToken cancellationToken)
3131
{

src/SqlStreamStore.HAL/Resources/AllStreamResource.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class AllStreamResource : IResource
1313
{
1414
private readonly IStreamStore _streamStore;
1515

16-
public HttpMethod[] Options { get; } =
16+
public HttpMethod[] Allowed { get; } =
1717
{
1818
HttpMethod.Get,
1919
HttpMethod.Head,
@@ -27,19 +27,20 @@ public AllStreamResource(IStreamStore streamStore)
2727
_streamStore = streamStore;
2828
}
2929

30-
public async Task<Response> GetPage(
30+
public async Task<Response> Get(
3131
ReadAllStreamOperation operation,
3232
CancellationToken cancellationToken)
3333
{
3434
var page = await operation.Invoke(_streamStore, cancellationToken);
3535

3636
var streamMessages = page.Messages.OrderByDescending(m => m.Position).ToArray();
3737

38-
var payloads = await Task.WhenAll(streamMessages
39-
.Select(message => operation.EmbedPayload
40-
? message.GetJsonData(cancellationToken)
41-
: Task.FromResult<string>(null))
42-
.ToArray());
38+
var payloads = await Task.WhenAll(
39+
Array.ConvertAll(
40+
streamMessages,
41+
message => operation.EmbedPayload
42+
? message.GetJsonData(cancellationToken)
43+
: SkippedPayload.Instance));
4344

4445
var response = new Response(
4546
new HALResponse(new

src/SqlStreamStore.HAL/Resources/AppendStreamOperation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ private AppendStreamOperation(HttpRequest request)
4343
private AppendStreamOperation(HttpRequest request, JArray body)
4444
: this(request)
4545
{
46-
NewStreamMessages = body.Select(ParseNewStreamMessage)
47-
.ToArray();
46+
NewStreamMessages = body.Select(ParseNewStreamMessage).ToArray();
4847
}
4948

5049
private AppendStreamOperation(HttpRequest request, JObject body)

src/SqlStreamStore.HAL/Resources/IResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
internal interface IResource
66
{
7-
HttpMethod[] Options { get; }
7+
HttpMethod[] Allowed { get; }
88
}
99
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace SqlStreamStore.HAL.Resources
2+
{
3+
using System.Threading.Tasks;
4+
5+
internal static class SkippedPayload
6+
{
7+
public static readonly Task<string> Instance = Task.FromResult<string>(null);
8+
}
9+
}

0 commit comments

Comments
 (0)