-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from PinguApps/feature/better-doc-serialization
Better Document serialization
- Loading branch information
Showing
23 changed files
with
959 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace PinguApps.Appwrite.Shared; | ||
public static class Constants | ||
{ | ||
public const string Version = "1.0.4"; | ||
public const string Version = "1.1.1"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/PinguApps.Appwrite.Shared/Converters/SdkMarkerConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Shared.Converters; | ||
public class SdkMarkerConverter : JsonConverter<object> | ||
{ | ||
// Never actually converts anything | ||
public override bool CanConvert(Type typeToConvert) => false; | ||
|
||
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException(); | ||
|
||
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options) => throw new NotImplementedException(); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/PinguApps.Appwrite.Shared/Converters/UpdateDocumentRequestConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Requests.Databases; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
|
||
namespace PinguApps.Appwrite.Shared.Converters; | ||
public class UpdateDocumentRequestConverter : JsonConverter<UpdateDocumentRequest> | ||
{ | ||
public override UpdateDocumentRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, UpdateDocumentRequest value, JsonSerializerOptions options) | ||
{ | ||
var permissionsListConverter = new PermissionListConverter(); | ||
|
||
writer.WriteStartObject(); | ||
|
||
if (!options.IsInsideSdk()) | ||
{ | ||
writer.WriteString("$collectionId", value.CollectionId); | ||
writer.WriteString("$databaseId", value.DatabaseId); | ||
} | ||
|
||
if (value.Permissions is not null) | ||
{ | ||
writer.WritePropertyName("permissions"); | ||
permissionsListConverter.Write(writer, [.. value.Permissions], options); | ||
} | ||
|
||
if (value.Data.Count > 0) | ||
{ | ||
writer.WritePropertyName("data"); | ||
writer.WriteStartObject(); | ||
foreach (var kvp in value.Data) | ||
{ | ||
writer.WritePropertyName(kvp.Key); | ||
JsonSerializer.Serialize(writer, kvp.Value, options); | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/PinguApps.Appwrite.Shared/Utils/JsonSerializerOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Linq; | ||
using System.Text.Json; | ||
using PinguApps.Appwrite.Shared.Converters; | ||
|
||
namespace PinguApps.Appwrite.Shared.Utils; | ||
public static class JsonSerializerOptionsExtensions | ||
{ | ||
public static bool IsInsideSdk(this JsonSerializerOptions options) => options.Converters.Any(c => c is SdkMarkerConverter); | ||
} |
Oops, something went wrong.