Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pastesphere support #127

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ REPOS=(
"https://github.com/likeandscribe/frontpage.git"
"https://github.com/psky-atp/client.git"
"https://github.com/Gregoor/skylights.git"
"https://github.com/echo8/pastesphere.git"
)

PWD=$(pwd)
Expand Down
1 change: 1 addition & 0 deletions src/FishyFlip/Lexicon/ATObject.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ namespace FishyFlip.Lexicon
[JsonDerivedType(typeof(App.Bsky.Unspecced.SkeletonSearchActor), typeDiscriminator: "app.bsky.unspecced.defs#skeletonSearchActor")]
[JsonDerivedType(typeof(App.Bsky.Unspecced.SkeletonSearchPost), typeDiscriminator: "app.bsky.unspecced.defs#skeletonSearchPost")]
[JsonDerivedType(typeof(App.Bsky.Unspecced.SkeletonSearchStarterPack), typeDiscriminator: "app.bsky.unspecced.defs#skeletonSearchStarterPack")]
[JsonDerivedType(typeof(Link.Pastesphere.Snippet), typeDiscriminator: "link.pastesphere.snippet")]
[JsonDerivedType(typeof(App.Bsky.Graph.Starterpack), typeDiscriminator: "app.bsky.graph.starterpack")]
[JsonDerivedType(typeof(App.Bsky.Graph.StarterPackView), typeDiscriminator: "app.bsky.graph.defs#starterPackView")]
[JsonDerivedType(typeof(App.Bsky.Graph.StarterPackViewBasic), typeDiscriminator: "app.bsky.graph.defs#starterPackViewBasic")]
Expand Down
2 changes: 2 additions & 0 deletions src/FishyFlip/Lexicon/CborExtensions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ public static ATObject ToATObject(this CBORObject obj)
return new App.Bsky.Unspecced.SkeletonSearchPost(obj);
case "app.bsky.unspecced.defs#skeletonSearchStarterPack":
return new App.Bsky.Unspecced.SkeletonSearchStarterPack(obj);
case "link.pastesphere.snippet":
return new Link.Pastesphere.Snippet(obj);
case "app.bsky.graph.starterpack":
return new App.Bsky.Graph.Starterpack(obj);
case "app.bsky.graph.defs#starterPackView":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// <auto-generated />
// This file was generated by FFSourceGen.
// Do not modify this file.

#nullable enable

using FishyFlip.Lexicon.Com.Atproto.Repo;

namespace FishyFlip.Lexicon.Link.Pastesphere
{

/// <summary>
/// Extension methods for link.pastesphere.
/// </summary>
public static class ATProtoPastesphereExtensions
{

/// <summary>
/// Create a Snippet record.
/// </summary>
/// <param name="atp"></param>
/// <param name="record"></param>
/// <param name="rkey"></param>
/// <param name="validate"></param>
/// <param name="swapCommit"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<CreateRecordOutput?>> CreateSnippetAsync(this FishyFlip.ATProtocol atp, Link.Pastesphere.Snippet record, string? rkey = default, bool? validate = default, string? swapCommit = default, CancellationToken cancellationToken = default)
{
return atp.CreateRecordAsync(atp.SessionManager.Session?.Did ?? throw new InvalidOperationException("Session did is required."), "link.pastesphere.snippet", record, rkey, validate, swapCommit, cancellationToken);
}

/// <summary>
/// Create a Snippet record.
/// </summary>
/// <param name="repo"></param>
/// <param name="collection"></param>
/// <param name="record"></param>
/// <param name="rkey"></param>
/// <param name="validate"></param>
/// <param name="swapCommit"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<CreateRecordOutput?>> CreateSnippetAsync(this FishyFlip.ATProtocol atp, string? title, string? type, string? body, string? description = default, DateTime? createdAt = default, string? rkey = default, bool? validate = default, string? swapCommit = default, CancellationToken cancellationToken = default)
{
var record = new FishyFlip.Lexicon.Link.Pastesphere.Snippet();
record.Title = title;
record.Description = description;
record.TypeValue = type;
record.Body = body;
record.CreatedAt = createdAt ?? DateTime.UtcNow;
return atp.CreateRecordAsync(atp.SessionManager.Session?.Did ?? throw new InvalidOperationException("Session did is required."), "link.pastesphere.snippet", record, rkey, validate, swapCommit, cancellationToken);
}

/// <summary>
/// Delete a Snippet record.
/// </summary>
/// <param name="atp"></param>
/// <param name="repo"></param>
/// <param name="rkey"></param>
/// <param name="swapRecord"></param>
/// <param name="swapCommit"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<DeleteRecordOutput?>> DeleteSnippetAsync(this FishyFlip.ATProtocol atp, FishyFlip.Models.ATIdentifier repo, string rkey, string? swapRecord = default, string? swapCommit = default, CancellationToken cancellationToken = default)
{
return atp.DeleteRecordAsync(repo, "link.pastesphere.snippet", rkey, swapRecord, swapCommit, cancellationToken);
}

/// <summary>
/// Put a Snippet record.
/// </summary>
/// <param name="atp"></param>
/// <param name="repo"></param>
/// <param name="rkey"></param>
/// <param name="record"></param>
/// <param name="validate"></param>
/// <param name="swapRecord"></param>
/// <param name="swapCommit"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<PutRecordOutput?>> PutSnippetAsync(this FishyFlip.ATProtocol atp, FishyFlip.Models.ATIdentifier repo, string rkey, Link.Pastesphere.Snippet record, bool? validate = default, string? swapRecord = default, string? swapCommit = default, CancellationToken cancellationToken = default)
{
return atp.PutRecordAsync(repo, "link.pastesphere.snippet", rkey, record, validate, swapRecord, swapCommit, cancellationToken);
}

/// <summary>
/// List Snippet records.
/// </summary>
/// <param name="atp"></param>
/// <param name="repo"></param>
/// <param name="limit"></param>
/// <param name="cursor"></param>
/// <param name="reverse"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<ListRecordsOutput?>> ListSnippetAsync(this FishyFlip.ATProtocol atp, FishyFlip.Models.ATIdentifier repo, int? limit = 50, string? cursor = default, bool? reverse = default, CancellationToken cancellationToken = default)
{
return atp.ListRecordsAsync(repo, "link.pastesphere.snippet", limit, cursor, reverse, cancellationToken);
}

/// <summary>
/// List Snippet records.
/// </summary>
/// <param name="atp"></param>
/// <param name="limit"></param>
/// <param name="cursor"></param>
/// <param name="reverse"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<ListRecordsOutput?>> ListSnippetAsync(this FishyFlip.ATProtocol atp, int? limit = 50, string? cursor = default, bool? reverse = default, CancellationToken cancellationToken = default)
{
return atp.ListRecordsAsync(atp.SessionManager.Session?.Did ?? throw new InvalidOperationException("Session did is required."), "link.pastesphere.snippet", limit, cursor, reverse, cancellationToken);
}

/// <summary>
/// Get Snippet records.
/// </summary>
/// <param name="atp"></param>
/// <param name="repo"></param>
/// <param name="rkey"></param>
/// <param name="cid"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<GetRecordOutput?>> GetSnippetAsync(this FishyFlip.ATProtocol atp, FishyFlip.Models.ATIdentifier repo, string rkey, string? cid = default, CancellationToken cancellationToken = default)
{
return atp.GetRecordAsync(repo, "link.pastesphere.snippet", rkey, cid, cancellationToken);
}

/// <summary>
/// Get Snippet records.
/// </summary>
/// <param name="atp"></param>
/// <param name="rkey"></param>
/// <param name="cid"></param>
/// <param name="cancellationToken"></param>
public static Task<Result<GetRecordOutput?>> GetSnippetAsync(this FishyFlip.ATProtocol atp, string rkey, string? cid = default, CancellationToken cancellationToken = default)
{
return atp.GetRecordAsync(atp.SessionManager.Session?.Did ?? throw new InvalidOperationException("Session did is required."), "link.pastesphere.snippet", rkey, cid, cancellationToken);
}
}
}

102 changes: 102 additions & 0 deletions src/FishyFlip/Lexicon/Link/Pastesphere/Snippet.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// <auto-generated />
// This file was generated by FFSourceGen.
// Do not modify this file.

#nullable enable

namespace FishyFlip.Lexicon.Link.Pastesphere
{
/// <summary>
/// Record representing a text snippet.
/// </summary>
public partial class Snippet : ATObject
{

/// <summary>
/// Initializes a new instance of the <see cref="Snippet"/> class.
/// </summary>
/// <param name="title"></param>
/// <param name="type"></param>
/// <param name="body"></param>
/// <param name="description"></param>
/// <param name="createdAt"></param>
public Snippet(string? title, string? type, string? body, string? description = default, DateTime? createdAt = default)
{
this.Title = title;
this.Description = description;
this.TypeValue = type;
this.Body = body;
this.CreatedAt = createdAt ?? DateTime.UtcNow;
}


/// <summary>
/// Initializes a new instance of the <see cref="Snippet"/> class.
/// </summary>
public Snippet()
{
}


/// <summary>
/// Initializes a new instance of the <see cref="Snippet"/> class.
/// </summary>
public Snippet(CBORObject obj)
{
if (obj["title"] is not null) this.Title = obj["title"].AsString();
if (obj["description"] is not null) this.Description = obj["description"].AsString();
if (obj["type"] is not null) this.TypeValue = obj["type"].AsString();
if (obj["body"] is not null) this.Body = obj["body"].AsString();
if (obj["createdAt"] is not null) this.CreatedAt = obj["createdAt"].ToDateTime();
}

/// <summary>
/// Gets or sets the title.
/// </summary>
[JsonPropertyName("title")]
public string? Title { get; set; }

/// <summary>
/// Gets or sets the description.
/// </summary>
[JsonPropertyName("description")]
public string? Description { get; set; }

/// <summary>
/// Gets or sets the type.
/// </summary>
[JsonPropertyName("type")]
public string? TypeValue { get; set; }

/// <summary>
/// Gets or sets the body.
/// </summary>
[JsonPropertyName("body")]
public string? Body { get; set; }

/// <summary>
/// Gets or sets the createdAt.
/// </summary>
[JsonPropertyName("createdAt")]
public DateTime? CreatedAt { get; set; } = DateTime.UtcNow;

/// <summary>
/// Gets the ATRecord Type.
/// </summary>
[JsonPropertyName("$type")]
public override string Type => "link.pastesphere.snippet";

public const string RecordType = "link.pastesphere.snippet";

public override string ToJson()
{
return JsonSerializer.Serialize<Link.Pastesphere.Snippet>(this, (JsonTypeInfo<Link.Pastesphere.Snippet>)SourceGenerationContext.Default.LinkPastesphereSnippet)!;
}

public static Snippet FromJson(string json)
{
return JsonSerializer.Deserialize<Link.Pastesphere.Snippet>(json, (JsonTypeInfo<Link.Pastesphere.Snippet>)SourceGenerationContext.Default.LinkPastesphereSnippet)!;
}
}
}

2 changes: 2 additions & 0 deletions src/FishyFlip/Lexicon/SourceGenerationContext.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ namespace FishyFlip.Lexicon
[JsonSerializable(typeof(List<FishyFlip.Lexicon.App.Bsky.Unspecced.SkeletonSearchPost>), TypeInfoPropertyName = "ListAppBskyUnspeccedSkeletonSearchPost")]
[JsonSerializable(typeof(FishyFlip.Lexicon.App.Bsky.Unspecced.SkeletonSearchStarterPack), TypeInfoPropertyName = "AppBskyUnspeccedSkeletonSearchStarterPack")]
[JsonSerializable(typeof(List<FishyFlip.Lexicon.App.Bsky.Unspecced.SkeletonSearchStarterPack>), TypeInfoPropertyName = "ListAppBskyUnspeccedSkeletonSearchStarterPack")]
[JsonSerializable(typeof(FishyFlip.Lexicon.Link.Pastesphere.Snippet), TypeInfoPropertyName = "LinkPastesphereSnippet")]
[JsonSerializable(typeof(List<FishyFlip.Lexicon.Link.Pastesphere.Snippet>), TypeInfoPropertyName = "ListLinkPastesphereSnippet")]
[JsonSerializable(typeof(FishyFlip.Lexicon.App.Bsky.Graph.Starterpack), TypeInfoPropertyName = "AppBskyGraphStarterpack")]
[JsonSerializable(typeof(List<FishyFlip.Lexicon.App.Bsky.Graph.Starterpack>), TypeInfoPropertyName = "ListAppBskyGraphStarterpack")]
[JsonSerializable(typeof(FishyFlip.Lexicon.App.Bsky.Graph.StarterPackView), TypeInfoPropertyName = "AppBskyGraphStarterPackView")]
Expand Down
4 changes: 2 additions & 2 deletions tools/FFSourceGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private async Task GenerateRecordExtensionClass(IGrouping<string, ClassGeneratio
sb.AppendLine($" var record = new {this.baseNamespace}.{item.FullClassName}();");
for (int i = 0; i < item.Properties.Count(); i++)
{
var prop = item.Properties[i].ClassName;
var prop = item.Properties[i].PropertyName;
var key = item.Properties[i].Key;
if (key == "createdAt")
{
Expand Down Expand Up @@ -722,7 +722,7 @@ private async Task GenerateRecordStaticExtensionClass(IGrouping<string, ClassGen
sb.AppendLine($" var record = new {this.baseNamespace}.{item.FullClassName}();");
for (int i = 0; i < item.Properties.Count(); i++)
{
var prop = item.Properties[i].ClassName;
var prop = item.Properties[i].PropertyName;
var key = item.Properties[i].Key;
if (key == "createdAt")
{
Expand Down
Loading