Skip to content

Commit

Permalink
WIP - Totally refactored (incompatible) API
Browse files Browse the repository at this point in the history
  • Loading branch information
monoman committed Apr 17, 2024
1 parent 2d4a2ac commit f6e7c29
Show file tree
Hide file tree
Showing 72 changed files with 867 additions and 1,056 deletions.
25 changes: 12 additions & 13 deletions InterlockLedger.Rest.Client/Abstractions/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
//
// ******************************************************************************************************************************

namespace InterlockLedger.Rest.Client
namespace InterlockLedger.Rest.Client;

internal static class Globals
{
internal static class Globals
{
public static readonly JsonSerializerOptions JsonSettings = new() {
AllowTrailingCommas = true,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
ReadCommentHandling = JsonCommentHandling.Skip,
WriteIndented = true,
PreferredObjectCreationHandling = JsonObjectCreationHandling.Replace,
};
}
public static readonly JsonSerializerOptions JsonSettings = new() {
AllowTrailingCommas = true,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
ReadCommentHandling = JsonCommentHandling.Skip,
WriteIndented = true,
PreferredObjectCreationHandling = JsonObjectCreationHandling.Replace,
};
}
48 changes: 22 additions & 26 deletions InterlockLedger.Rest.Client/Abstractions/RestAbstractChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,43 @@
namespace InterlockLedger.Rest.Client.Abstractions;

[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
public abstract class RestAbstractChain : IRestChain
public abstract class RestAbstractChain<T> : IRestChain where T : IRestChain
{
public string Id { get; }
IRestInterlockings IRestChain.Interlockings => _interlockings;
public string Name { get; }
public IInterlockings Interlockings { get; }
public string? Name { get; }

IRestRecords IRestChain.Records => _records;
public IRecordsStore Records { get; }

IRestRecordsAsJson IRestChain.RecordsAsJson => _recordsAsJson;
public IRecordsAsJsonStore RecordsAsJson { get; }

Task<IEnumerable<ulong>> IRestChain.GetActiveAppsAsync() => _rest.GetAsync<IEnumerable<ulong>>($"/chain/{Id}/activeApps");
public Task<IEnumerable<ulong>?> GetActiveAppsAsync() => _node.GetAsync<IEnumerable<ulong>>($"/chain/{Id}/activeApps");

Task<IEnumerable<KeyModel>> IRestChain.GetPermittedKeysAsync() => _rest.GetAsync<IEnumerable<KeyModel>>($"/chain/{Id}/key");
public Task<IEnumerable<KeyModel>?> GetPermittedKeysAsync() => _node.GetAsync<IEnumerable<KeyModel>>($"/chain/{Id}/key");

Task<ChainSummaryModel> IRestChain.GetSummaryAsync() => _rest.GetAsync<ChainSummaryModel>($"/chain/{Id}");
public Task<ChainSummaryModel?> GetSummaryAsync() => _node.GetAsync<ChainSummaryModel>($"/chain/{Id}");

Task<IEnumerable<ulong>> IRestChain.PermitAppsAsync(params ulong[] appsToPermit)
=> _rest.PostAsync<IEnumerable<ulong>>($"/chain/{Id}/activeApps", appsToPermit);
public Task<IEnumerable<ulong>?> PermitAppsAsync(params ulong[] appsToPermit)
=> _node.PostAsync<IEnumerable<ulong>>($"/chain/{Id}/activeApps", appsToPermit);

Task<IEnumerable<KeyModel>> IRestChain.PermitKeysAsync(params KeyPermitModel[] keysToPermit)
=> _rest.PostAsync<IEnumerable<KeyModel>>($"/chain/{Id}/key", keysToPermit);
public Task<IEnumerable<KeyModel>?> PermitKeysAsync(params KeyPermitModel[] keysToPermit)
=> _node.PostAsync<IEnumerable<KeyModel>>($"/chain/{Id}/key", keysToPermit);

public Task<PageOf<RecordModel>> RecordsFromAsync(ulong firstSerial)
=> _rest.GetAsync<PageOf<RecordModel>>($"records@{Id}?firstSerial={firstSerial}");
public Task<PageOf<RecordModel>?> RecordsFromAsync(ulong firstSerial)
=> _node.GetAsync<PageOf<RecordModel>>($"records@{Id}?firstSerial={firstSerial}");

public override string ToString() => $"Chain '{Name}' #{Id}";

internal readonly IRestNodeInternals _rest;
internal readonly RestAbstractNode<T> _node;

internal RestAbstractChain(IRestNodeInternals rest, ChainIdModel chainId) {
_rest = rest.Required();
Id = chainId.Required().Id;
internal RestAbstractChain(RestAbstractNode<T> node, ChainIdModel chainId) {
_node = node.Required();
Id = chainId.Required().Id.Required();
Name = chainId.Name;
_records = new RecordsImplementation(this);
_recordsAsJson = new RecordsAsJsonImplementation(this);
_interlockings = new InterlockingsImplementation(this);
Records = new RecordsStoreImplementation<T>(this);
RecordsAsJson = new RecordsAsJsonStoreImplementation<T>(this);
Interlockings = new InterlockingsImplementation<T>(this);
}

private readonly IRestInterlockings _interlockings;
private readonly IRestRecords _records;
private readonly IRestRecordsAsJson _recordsAsJson;

private string GetDebuggerDisplay() => $"{this} at {_rest}";
private string GetDebuggerDisplay() => $"{this} at {_node}";
}
Loading

0 comments on commit f6e7c29

Please sign in to comment.