Skip to content

Commit

Permalink
Merge branch 'master' into bfops/prevent-master-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bfops authored Aug 29, 2024
2 parents 15dba19 + 732dd28 commit 3271a0f
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 73 deletions.
17 changes: 14 additions & 3 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Notes for maintainers

## `SpacetimeDB.ClientApi`
## `ClientApi.cs`

To regenerate this namespace, run the `tools/gen-client-api.sh` or the
`tools/gen-client-api.bat` script.
The file `ClientApi.cs` is generated by [ProtoBuf](https://protobuf.dev/)
from [the SpacetimeDB client-api-messages proto definition](https://github.com/clockworklabs/SpacetimeDB/blob/master/crates/client-api-messages/protobuf/client_api.proto).
This is not automated.
Whenever the `client_api.proto` changes, you'll have to manually re-run `protoc` to re-generate the definitions.

```sh
cd ~/clockworklabs/SpacetimeDB/crates/client-api-messages/protobuf
protoc --csharp_out=/absolute/path/to/spacetimedb-csharp-sdk/src \
./client_api.proto
```

Note that `protoc` cannot understand paths that start with `~`;
you must write the absolute path starting from `/`.
5 changes: 3 additions & 2 deletions SpacetimeDB.ClientSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<LangVersion>9</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>SpacetimeDB.ClientSDK</PackageId>
<Title>SpacetimeDB SDK</Title>
<Authors>jdetter</Authors>
Expand All @@ -16,15 +17,15 @@
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/clockworklabs/spacetimedb-csharp-sdk</RepositoryUrl>
<AssemblyVersion>0.12.0</AssemblyVersion>
<AssemblyVersion>0.11.0</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<DefaultItemExcludes>$(DefaultItemExcludes);*~/**</DefaultItemExcludes>
<!-- We want to save DLLs for Unity which doesn't support NuGet. -->
<RestorePackagesPath>packages</RestorePackagesPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SpacetimeDB.BSATN.Runtime" Version="0.12.*" />
<PackageReference Include="SpacetimeDB.BSATN.Runtime" Version="0.11.*" />

<InternalsVisibleTo Include="SpacetimeDB.Tests" />
</ItemGroup>
Expand Down
83 changes: 83 additions & 0 deletions src/Primitives.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using SpacetimeDB.BSATN;

using System;
using System.IO;

namespace SpacetimeDB
{

public struct I128 : IEquatable<I128>
{
public long hi;
public ulong lo;

public I128(long hi, ulong lo)
{
this.hi = hi;
this.lo = lo;
}

public readonly bool Equals(I128 x) => hi == x.hi && lo == x.lo;

public override readonly bool Equals(object? o) => o is I128 x && Equals(x);

public static bool operator ==(I128 a, I128 b) => a.Equals(b);
public static bool operator !=(I128 a, I128 b) => !a.Equals(b);

public override readonly int GetHashCode() => hi.GetHashCode() ^ lo.GetHashCode();

public override readonly string ToString() => $"I128({hi},{lo})";

public readonly struct BSATN : IReadWrite<I128>
{
public I128 Read(BinaryReader reader) => new(reader.ReadInt64(), reader.ReadUInt64());

public void Write(BinaryWriter writer, I128 value)
{
writer.Write(value.hi);
writer.Write(value.lo);
}

public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
new AlgebraicType.Builtin(new BuiltinType.I128(new Unit()));
}
}

public struct U128 : IEquatable<U128>
{
public ulong hi;
public ulong lo;

public U128(ulong hi, ulong lo)
{
this.lo = lo;
this.hi = hi;
}

public readonly bool Equals(U128 x) => hi == x.hi && lo == x.lo;

public override readonly bool Equals(object? o) => o is U128 x && Equals(x);

public static bool operator ==(U128 a, U128 b) => a.Equals(b);
public static bool operator !=(U128 a, U128 b) => !a.Equals(b);

public override readonly int GetHashCode() => hi.GetHashCode() ^ lo.GetHashCode();

public override readonly string ToString() => $"U128({hi},{lo})";

public readonly struct BSATN : IReadWrite<U128>
{
public U128 Read(BinaryReader reader) => new(reader.ReadUInt64(), reader.ReadUInt64());

public void Write(BinaryWriter writer, U128 value)
{
writer.Write(value.hi);
writer.Write(value.lo);
}

public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>
new AlgebraicType.Builtin(new BuiltinType.U128(new Unit()));
}
}

}
5 changes: 3 additions & 2 deletions src/SpacetimeDB/ClientApi/CallReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class CallReducer
{
[DataMember(Name = "reducer")]
public string Reducer = "";

[DataMember(Name = "args")]
public SpacetimeDB.ClientApi.EncodedValue Args = null!;

[DataMember(Name = "request_id")]
public uint RequestId;

}
}
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/ClientMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#nullable enable

using System;
using SpacetimeDB;

namespace SpacetimeDB.ClientApi
{
Expand Down
3 changes: 1 addition & 2 deletions src/SpacetimeDB/ClientApi/DatabaseUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class DatabaseUpdate
{
[DataMember(Name = "tables")]
public System.Collections.Generic.List<SpacetimeDB.ClientApi.TableUpdate> Tables = new();

}
}
3 changes: 1 addition & 2 deletions src/SpacetimeDB/ClientApi/EnergyQuanta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class EnergyQuanta
{
[DataMember(Name = "quanta")]
public U128 Quanta;

}
}
5 changes: 3 additions & 2 deletions src/SpacetimeDB/ClientApi/IdentityToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class IdentityToken
{
[DataMember(Name = "identity")]
public SpacetimeDB.Identity Identity = new();

[DataMember(Name = "token")]
public string Token = "";

[DataMember(Name = "address")]
public SpacetimeDB.Address Address = new();

}
}
5 changes: 3 additions & 2 deletions src/SpacetimeDB/ClientApi/InitialSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class InitialSubscription
{
[DataMember(Name = "database_update")]
public SpacetimeDB.ClientApi.DatabaseUpdate DatabaseUpdate = new();

[DataMember(Name = "request_id")]
public uint RequestId;

[DataMember(Name = "total_host_execution_duration_micros")]
public ulong TotalHostExecutionDurationMicros;

}
}
4 changes: 2 additions & 2 deletions src/SpacetimeDB/ClientApi/OneOffQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class OneOffQuery
{
[DataMember(Name = "message_id")]
public byte[] MessageId = Array.Empty<byte>();

[DataMember(Name = "query_string")]
public string QueryString = "";

}
}
8 changes: 5 additions & 3 deletions src/SpacetimeDB/ClientApi/OneOffQueryResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class OneOffQueryResponse
{
[DataMember(Name = "message_id")]
public byte[] MessageId = Array.Empty<byte>();

[DataMember(Name = "error")]
public string? Error;

[DataMember(Name = "tables")]
public System.Collections.Generic.List<SpacetimeDB.ClientApi.OneOffTable> Tables = new();
public List<SpacetimeDB.ClientApi.OneOffTable> Tables = new();

[DataMember(Name = "total_host_execution_duration_micros")]
public ulong TotalHostExecutionDurationMicros;

}
}
6 changes: 3 additions & 3 deletions src/SpacetimeDB/ClientApi/OneOffTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class OneOffTable
{
[DataMember(Name = "table_name")]
public string TableName = "";
[DataMember(Name = "rows")]
public System.Collections.Generic.List<SpacetimeDB.ClientApi.EncodedValue> Rows = new();

[DataMember(Name = "rows")]
public List<SpacetimeDB.ClientApi.EncodedValue> Rows = new();
}
}
6 changes: 4 additions & 2 deletions src/SpacetimeDB/ClientApi/ReducerCallInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class ReducerCallInfo
{
[DataMember(Name = "reducer_name")]
public string ReducerName = "";

[DataMember(Name = "reducer_id")]
public uint ReducerId;

[DataMember(Name = "args")]
public SpacetimeDB.ClientApi.EncodedValue Args = null!;

[DataMember(Name = "request_id")]
public uint RequestId;

}
}
1 change: 0 additions & 1 deletion src/SpacetimeDB/ClientApi/ServerMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#nullable enable

using System;
using SpacetimeDB;

namespace SpacetimeDB.ClientApi
{
Expand Down
4 changes: 2 additions & 2 deletions src/SpacetimeDB/ClientApi/Subscribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class Subscribe
{
[DataMember(Name = "query_strings")]
public System.Collections.Generic.List<string> QueryStrings = new();

[DataMember(Name = "request_id")]
public uint RequestId;

}
}
10 changes: 6 additions & 4 deletions src/SpacetimeDB/ClientApi/TableUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@

namespace SpacetimeDB.ClientApi
{
[SpacetimeDB.Type]
[DataContract]
[SpacetimeDB.Type]
public partial class TableUpdate
{
[DataMember(Name = "table_id")]
public uint TableId;

[DataMember(Name = "table_name")]
public string TableName = "";

[DataMember(Name = "deletes")]
public System.Collections.Generic.List<SpacetimeDB.ClientApi.EncodedValue> Deletes = new();
[DataMember(Name = "inserts")]
public System.Collections.Generic.List<SpacetimeDB.ClientApi.EncodedValue> Inserts = new();
public List<SpacetimeDB.ClientApi.EncodedValue> Deletes = new();

[DataMember(Name = "inserts")]
public List<SpacetimeDB.ClientApi.EncodedValue> Inserts = new();
}
}
7 changes: 6 additions & 1 deletion src/SpacetimeDB/ClientApi/TransactionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ public partial class TransactionUpdate
{
[DataMember(Name = "status")]
public SpacetimeDB.ClientApi.UpdateStatus Status = null!;

[DataMember(Name = "timestamp")]
public SpacetimeDB.ClientApi.Timestamp Timestamp = new();

[DataMember(Name = "caller_identity")]
public SpacetimeDB.Identity CallerIdentity = new();

[DataMember(Name = "caller_address")]
public SpacetimeDB.Address CallerAddress = new();

[DataMember(Name = "reducer_call")]
public SpacetimeDB.ClientApi.ReducerCallInfo ReducerCall = new();

[DataMember(Name = "energy_quanta_used")]
public SpacetimeDB.ClientApi.EnergyQuanta EnergyQuantaUsed = new();

[DataMember(Name = "host_execution_duration_micros")]
public ulong HostExecutionDurationMicros;

}
}
Loading

0 comments on commit 3271a0f

Please sign in to comment.