Skip to content

Commit

Permalink
Chore/drop json support (surrealdb#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno authored Oct 4, 2024
1 parent 974d731 commit 12c1fca
Show file tree
Hide file tree
Showing 214 changed files with 2,146 additions and 7,094 deletions.
7 changes: 3 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">false</IsAotCompatible>

<IsPackable>false</IsPackable>
<Version>0.5.1</Version>
Expand All @@ -28,11 +27,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.27.3">
<PackageReference Include="CSharpier.MsBuild">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
<PackageReference Include="DotNet.ReproducibleBuilds">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
38 changes: 38 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.10" />
<PackageVersion Include="Bogus" Version="35.5.1" />
<PackageVersion Include="ConcurrentHashSet" Version="1.3.0" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="csbindgen" Version="1.9.1" />
<PackageVersion Include="CSharpier.MsBuild" Version="0.27.3" />
<PackageVersion Include="Dahomey.Cbor" Version="1.24.3" />
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Meziantou.Xunit.ParallelTestFramework" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.Reactive.Testing" Version="6.0.1" />
<PackageVersion Include="Microsoft.Spatial" Version="7.18.0" />
<PackageVersion Include="MudBlazor" Version="6.11.2" />
<PackageVersion Include="Pidgin" Version="3.2.3" />
<PackageVersion Include="Semver" Version="2.3.0" />
<PackageVersion Include="Superpower" Version="3.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="SystemTextJsonPatch" Version="3.2.0" />
<PackageVersion Include="Ulid" Version="1.3.3" />
<PackageVersion Include="Websocket.Client" Version="5.1.1" />
<PackageVersion Include="xunit" Version="2.6.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
</Project>
38 changes: 15 additions & 23 deletions SurrealDb.Embedded.InMemory/Internals/SurrealDbEngine.InMemory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using System.Reactive;
using System.Runtime.InteropServices;
using Dahomey.Cbor;
Expand All @@ -7,7 +7,6 @@
using SurrealDb.Net.Extensions.DependencyInjection;
using SurrealDb.Net.Internals;
using SurrealDb.Net.Internals.Cbor;
using SurrealDb.Net.Internals.Constants;
using SurrealDb.Net.Internals.Extensions;
using SurrealDb.Net.Internals.Models.LiveQuery;
using SurrealDb.Net.Internals.Stream;
Expand Down Expand Up @@ -52,13 +51,6 @@ public void Initialize(
_parameters = parameters;
_configureCborOptions = configureCborOptions;
_surrealDbLoggerFactory = surrealDbLoggerFactory;

if (_parameters.Serialization?.ToLowerInvariant() == SerializationConstants.JSON)
{
throw new NotSupportedException(
"The JSON serialization is not supported for the in-memory provider."
);
}
}

public Task Authenticate(Jwt jwt, CancellationToken cancellationToken)
Expand Down Expand Up @@ -193,9 +185,9 @@ await SendRequestAsync<Unit>(Method.Delete, [table], cancellationToken)
.ConfigureAwait(false);
}

public async Task<bool> Delete(Thing thing, CancellationToken cancellationToken)
public async Task<bool> Delete(RecordId recordId, CancellationToken cancellationToken)
{
var result = await SendRequestAsync<object?>(Method.Delete, [thing], cancellationToken)
var result = await SendRequestAsync<object?>(Method.Delete, [recordId], cancellationToken)
.ConfigureAwait(false);
return result is not null;
}
Expand Down Expand Up @@ -301,12 +293,12 @@ CancellationToken cancellationToken
}

public async Task<T> Merge<T>(
Thing thing,
RecordId recordId,
Dictionary<string, object> data,
CancellationToken cancellationToken
)
{
return await SendRequestAsync<T>(Method.Merge, [thing, data], cancellationToken)
return await SendRequestAsync<T>(Method.Merge, [recordId, data], cancellationToken)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -350,13 +342,13 @@ CancellationToken cancellationToken
}

public async Task<T> Patch<T>(
Thing thing,
RecordId recordId,
JsonPatchDocument<T> patches,
CancellationToken cancellationToken
)
where T : class
{
return await SendRequestAsync<T>(Method.Patch, [thing, patches], cancellationToken)
return await SendRequestAsync<T>(Method.Patch, [recordId, patches], cancellationToken)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -431,8 +423,8 @@ CancellationToken cancellationToken

public async Task<IEnumerable<TOutput>> Relate<TOutput, TData>(
string table,
IEnumerable<Thing> ins,
IEnumerable<Thing> outs,
IEnumerable<RecordId> ins,
IEnumerable<RecordId> outs,
TData? data,
CancellationToken cancellationToken
)
Expand All @@ -447,17 +439,17 @@ CancellationToken cancellationToken
}

public async Task<TOutput> Relate<TOutput, TData>(
Thing thing,
Thing @in,
Thing @out,
RecordId recordId,
RecordId @in,
RecordId @out,
TData? data,
CancellationToken cancellationToken
)
where TOutput : class
{
return await SendRequestAsync<TOutput>(
Method.Relate,
[@in, thing, @out, data],
[@in, recordId, @out, data],
cancellationToken
)
.ConfigureAwait(false);
Expand All @@ -469,9 +461,9 @@ public async Task<IEnumerable<T>> Select<T>(string table, CancellationToken canc
.ConfigureAwait(false);
}

public async Task<T?> Select<T>(Thing thing, CancellationToken cancellationToken)
public async Task<T?> Select<T>(RecordId recordId, CancellationToken cancellationToken)
{
return await SendRequestAsync<T?>(Method.Select, [thing], cancellationToken)
return await SendRequestAsync<T?>(Method.Select, [recordId], cancellationToken)
.ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
Expand All @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="csbindgen" Version="1.9.1">
<PackageReference Include="csbindgen">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
10 changes: 0 additions & 10 deletions SurrealDb.Embedded.InMemory/SurrealDbMemoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,5 @@ internal SurrealDbMemoryClient(
InitializeProviderEngine(engine, parameters, configureCborOptions, loggerFactory);

_engine = engine;

if (parameters.Username is not null)
Configure(
parameters.Namespace,
parameters.Database,
parameters.Username,
parameters.Password
);
else
Configure(parameters.Namespace, parameters.Database, parameters.Token);
}
}
6 changes: 3 additions & 3 deletions SurrealDb.Examples.Blazor.Server/Models/ColumnRecord.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using Dahomey.Cbor.Attributes;
using SurrealDb.Net.Models;

namespace SurrealDb.Examples.Blazor.Server.Models;
Expand All @@ -9,8 +9,8 @@ public class ColumnRecord : Record

public string Name { get; set; } = string.Empty;
public int Order { get; set; }
public IEnumerable<Thing> Tasks { get; set; } = Array.Empty<Thing>();
public IEnumerable<RecordId> Tasks { get; set; } = Array.Empty<RecordId>();

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[CborIgnoreIfDefault]
public DateTime CreatedAt { get; set; }
}
2 changes: 1 addition & 1 deletion SurrealDb.Examples.Blazor.Server/Models/CreateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class CreateTask : Record

public string Title { get; set; } = string.Empty;
public DateTime DueDate { get; set; }
public Thing Column { get; set; } = null!;
public RecordId Column { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion SurrealDb.Examples.Blazor.Server/Models/DeleteTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class DeleteTask : Record
{
internal const string Table = "delete_task";

public Thing Task { get; set; } = null!;
public RecordId Task { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion SurrealDb.Examples.Blazor.Server/Models/DisplayableTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SurrealDb.Examples.Blazor.Server.Models;

public class DisplayableTask
{
public Thing Id { get; set; } = null!;
public RecordId Id { get; set; } = null!;
public string Title { get; set; } = string.Empty;
public DateTime DueDate { get; set; }
}
6 changes: 3 additions & 3 deletions SurrealDb.Examples.Blazor.Server/Models/MoveTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class MoveTask : Record
{
internal const string Table = "move_task";

public Thing Task { get; set; } = null!;
public Thing From { get; set; } = null!;
public Thing To { get; set; } = null!;
public RecordId Task { get; set; } = null!;
public RecordId From { get; set; } = null!;
public RecordId To { get; set; } = null!;
public int NewIndex { get; set; }
}
4 changes: 2 additions & 2 deletions SurrealDb.Examples.Blazor.Server/Models/TaskRecord.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using Dahomey.Cbor.Attributes;
using SurrealDb.Net.Models;

namespace SurrealDb.Examples.Blazor.Server.Models;
Expand All @@ -10,6 +10,6 @@ public class TaskRecord : Record
public string Title { get; set; } = string.Empty;
public DateTime DueDate { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[CborIgnoreIfDefault]
public DateTime CreatedAt { get; set; }
}
8 changes: 4 additions & 4 deletions SurrealDb.Examples.Blazor.Server/Pages/RealtimeBoard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ else
_loading = false;

_subscription = Client.ObserveTable<DisplayableColumn>(DisplayableColumn.Table)
.ScanRecords(_columns.ToDictionary(c => c.Id!.ToString()))
.ScanRecords(_columns.ToDictionary(c => c.Id!.DeserializeId<string>()))
.Subscribe(async columnsAsDictionary =>
{
await InvokeAsync(() =>
Expand Down Expand Up @@ -122,8 +122,8 @@ else
var moveTask = new MoveTask
{
Task = task.Id!,
From = Thing.From(ColumnRecord.Table, fromColumn.Id!.Id),
To = Thing.From(ColumnRecord.Table, toColumn.Id!.Id),
From = RecordId.From(ColumnRecord.Table, fromColumn.Id!.DeserializeId<string>()),
To = RecordId.From(ColumnRecord.Table, toColumn.Id!.DeserializeId<string>()),
NewIndex = newIndex
};
return Client.Create(MoveTask.Table, moveTask);
Expand All @@ -144,7 +144,7 @@ else

private Task CreateTaskAsync(DisplayableColumn column, AddTaskForm formData)
{
var columnId = Thing.From(ColumnRecord.Table, column.Id!.Id);
var columnId = RecordId.From(ColumnRecord.Table, column.Id!.DeserializeId<string>());

var @event = new CreateTask
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.5.1" />
<PackageReference Include="MudBlazor" Version="6.11.2" />
<PackageReference Include="Bogus" />
<PackageReference Include="MudBlazor" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.5.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Bogus" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion SurrealDb.Examples.TodoApi.Aot/Models/Todo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Todo() { }

public Todo(int id, string title, DateOnly? dueBy = null, bool isComplete = false)
{
Id = Thing.From(Table, id);
Id = RecordId.From(Table, id);
Title = title;
DueBy = dueBy;
IsComplete = isComplete;
Expand Down
10 changes: 4 additions & 6 deletions SurrealDb.Examples.TodoApi.Aot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using SurrealDb.Examples.TodoApi.Aot.Models;
using SurrealDb.Net;

// TODO : Handle AOT via CborSerializerContext

HandleTimeoutFromArgs(args);

var builder = WebApplication.CreateSlimBuilder(args);
Expand All @@ -15,10 +17,7 @@
});

JsonSerializerContext[] jsonSerializerContexts = { AppJsonSerializerContext.Default };
services.AddSurreal(
configuration.GetConnectionString("SurrealDB")!,
appendJsonSerializerContexts: () => jsonSerializerContexts
);
services.AddSurreal(configuration.GetConnectionString("SurrealDB")!);

var app = builder.Build();

Expand Down Expand Up @@ -60,8 +59,7 @@ async Task InitializeDbAsync()
SurrealDbOptions
.Create()
.FromConnectionString(configuration.GetConnectionString("SurrealDB")!)
.Build(),
appendJsonSerializerContexts: () => jsonSerializerContexts
.Build()
);

var tasks = sampleTodos.Select(async todo =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="SystemTextJsonPatch" Version="3.2.0" />
<PackageReference Include="Bogus" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="SystemTextJsonPatch" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 12c1fca

Please sign in to comment.