Skip to content

Commit

Permalink
Add Type Script definition content generation of JSON schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcean committed Jan 7, 2025
1 parent abcb23a commit 6bcbfd8
Show file tree
Hide file tree
Showing 36 changed files with 761 additions and 133 deletions.
3 changes: 0 additions & 3 deletions Core/Collection/List/StringsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public static int WriteTo(this IEnumerable<ServerSentEventInfo> col, Stream stre
if (item == null) continue;
if (i > 0) writer.Write('\n');
writer.Write(item.ToResponseString(true));
writer.Write('\n');
writer.Flush();
i++;
}
Expand All @@ -96,7 +95,6 @@ public static async Task<int> WriteToAsync(this IEnumerable<ServerSentEventInfo>
if (item == null) continue;
if (i > 0) writer.Write('\n');
await writer.WriteAsync(item.ToResponseString(true));
writer.Write('\n');
await writer.FlushAsync();
i++;
}
Expand All @@ -123,7 +121,6 @@ public static async Task<int> WriteToAsync(this IAsyncEnumerable<ServerSentEvent
if (item == null) continue;
if (i > 0) writer.Write('\n');
await writer.WriteAsync(item.ToResponseString(true));
writer.Write('\n');
await writer.FlushAsync();
i++;
}
Expand Down
2 changes: 2 additions & 0 deletions Core/CommandLine/Console/StyleConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -17,6 +18,7 @@ namespace Trivial.CommandLine;
/// <summary>
/// The command line interface.
/// </summary>
[Guid("86E515F9-00B4-465A-ACB5-C473B7B678D4")]
public sealed partial class StyleConsole
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Core/Data/Reader/ColumnMapping.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

using Trivial.Text;
Expand All @@ -9,6 +10,7 @@ namespace Trivial.Data;
/// <summary>
/// Column mapping.
/// </summary>
[Guid("A11ACE29-8AD8-4A59-9C88-52053CDEF354")]
public class ColumnMapping : List<ColumnMappingItem>
{
/// <summary>
Expand Down Expand Up @@ -73,6 +75,7 @@ public static ColumnMapping Load(Type type)
/// <summary>
/// Column mapping item.
/// </summary>
[Guid("A6C96FD4-87BA-4076-8FC9-D37B859F9EFB")]
public class ColumnMappingItem
{
/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions Core/Data/Result/Change.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -334,6 +335,29 @@ public DataEventArgs(T data, string message) : this(data)
/// Gets the additional message.
/// </summary>
public string Message { get; }

/// <inheritdoc />
public override string ToString()
{
try
{
return Data?.ToString() ?? Message ?? "null";
}
catch (InvalidOperationException)
{
}
catch (NotSupportedException)
{
}
catch (NotImplementedException)
{
}
catch (ExternalException)
{
}

return base.ToString();
}
}

/// <summary>
Expand Down
17 changes: 16 additions & 1 deletion Core/Data/Result/CollectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,12 @@ internal JsonObjectNode ToJson()
/// The Server-Sent Events collection data result.
/// </summary>
/// <typeparam name="T">The type of item.</typeparam>
/// <example>
/// <code>
/// var http = new JsonHttpClient&lt;StreamingCollectionResult&lt;JsonObjectNode&gt;&gt;()
/// var sse = await http.GetAsync(A-URL-TO-STREAM-MESSAGE);
/// </code>
/// </example>
public class StreamingCollectionResult<T> : CollectionResult<T>
{
private Task task;
Expand Down Expand Up @@ -613,12 +619,21 @@ public StreamingCollectionResult(IAsyncEnumerable<ServerSentEventInfo> collectio
{
}

/// <summary>
/// Initializes a new instance of the CollectionResultSource class.
/// </summary>
/// <param name="sse">The Server-Sent Events stream.</param>
public StreamingCollectionResult(Stream sse)
: this(ServerSentEventInfo.ParseAsync(sse), null as Action<StreamingCollectionResult<T>, ServerSentEventInfo>, null)
{
}

/// <summary>
/// Initializes a new instance of the CollectionResultSource class.
/// </summary>
/// <param name="sse">The Server-Sent Events stream.</param>
/// <param name="options">The JSON serializer options.</param>
public StreamingCollectionResult(Stream sse, JsonSerializerOptions options = null)
public StreamingCollectionResult(Stream sse, JsonSerializerOptions options)
: this(ServerSentEventInfo.ParseAsync(sse), null as Action<StreamingCollectionResult<T>, ServerSentEventInfo>, options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions Core/IO/Stream/CharsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -12,6 +13,7 @@ namespace Trivial.IO;
/// <summary>
/// The characters reader.
/// </summary>
[Guid("B8BB09CE-3ADC-4E56-AF99-D7DF82FAA419")]
public class CharsReader : TextReader
{
private readonly IEnumerator<char> enumerator;
Expand Down
Loading

0 comments on commit 6bcbfd8

Please sign in to comment.