Skip to content

Commit

Permalink
Revert master to a stable state (#123)
Browse files Browse the repository at this point in the history
## Description of Changes
Revert `master` to the original state of this PR:
#53.

We should prevent merging into `master` from now on, since the
repositories are now merged.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testing
I loaded a bitcraft world and ran around.

I used the versions listed here:
clockworklabs/com.clockworklabs.spacetimedbsdk-archive#57

---------

Co-authored-by: Ingvar Stepanyan <[email protected]>
Co-authored-by: Zeke Foppa <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2024
1 parent a517717 commit 732dd28
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/)

This comment has been minimized.

Copy link
@RReverser

RReverser Aug 30, 2024

Author Member

@bfops This reversal doesn't look right. master doesn't have ClientApi.cs or Protobuf dependency anymore. On the other hand, we did have tools folder with scripts mentioned in this doc before reversal, but they were removed.

This comment has been minimized.

Copy link
@gefjon

gefjon Aug 30, 2024

Contributor

Yes, this file of documentation and the tools dir appear to have been reverted to their pre-protobufectomy state, but the contents of SpacetimeDB/ClientApi still appear to reflect a post-protobufectomy world.

This comment has been minimized.

Copy link
@RReverser

RReverser Aug 30, 2024

Author Member

Yeah I'm not sure which one is supposed to be master at the moment (pre-protobuf or post-) but right now code is inconsistent with docs.

This comment has been minimized.

Copy link
@gefjon

gefjon Aug 30, 2024

Contributor

The .csproj suggests 0.11, which IIRC is post-protobufectomy.

This comment has been minimized.

Copy link
@bfops

bfops Aug 30, 2024

Author Collaborator

@RReverser I can tell you that this is the state of #117 before I merged in master:

[09:28:01] ~/work/clockwork/com.clockworklabs.spacetimedbsdk
$ git reset --hard origin/master
HEAD is now at 732dd28 Revert `master` to a stable state (#123)

[09:28:03] ~/work/clockwork/com.clockworklabs.spacetimedbsdk
$ git diff a32d037

image

It was tested with BitCraft before merging.

Was there something wrong with the merge PR?

This comment has been minimized.

Copy link
@bfops

bfops Aug 30, 2024

Author Collaborator

We effectively reverted all changes applied after Minor BSATN simplifications:

732dd28 Revert `master` to a stable state (#123)
a517717 Merge Unity SDK into C# SDK (#117)
023440c Nix `Primitives.cs` - types now defined in main repo (#120)
fb0cd6b Update DEVELOP.md to reflect new codegen (#119)
c071e38 Restore `dotnet pack` functionality (#118)
293aa66 Don't use BuiltinType.I/U128, use AlgebraicType.I/U128 (#116)
7d94b10 Minor BSATN simplifications (#111)

Those PRs are now in the staging branch:

9904a02 (origin/staging, staging) Nix `Primitives.cs` - types now defined in main repo (#120)
5e612f3 Update DEVELOP.md to reflect new codegen (#119)
ae7c531 Restore `dotnet pack` functionality (#118)
9481380 Don't use BuiltinType.I/U128, use AlgebraicType.I/U128 (#116)
732dd28 (origin/master, origin/HEAD, master) Revert `master` to a stable state (#123)

This comment has been minimized.

Copy link
@RReverser

RReverser Aug 30, 2024

Author Member

5e612f3 should be cherry picked. It was landed in C# SDK already, just not ported over to Unity SDK repo, but that's the commit that updates docs and introduces new scripts.

You might have to rename the introduced tools folder to tools~ though so that it's ignored by Unity.

This comment has been minimized.

Copy link
@bfops

bfops Aug 30, 2024

Author Collaborator

Yes, but afaik it merged after a breaking change 293aa66 Don't use BuiltinType.I/U128, use AlgebraicType.I/U128 (#116). I believe this change only works with Spacetime 0.12+?

When we renamed this repo to be the Unity SDK repo, it took on new constraints - the master branch is essentially always released. But we didn't intend to immediately release all the breaking changes that had merged to spacetimedb-csharp-sdk.

Pointing BitCraftClient at fb0cd6b Update DEVELOP.md to reflect new codegen (#119) causes compilation errors.

Since it doesn't affect the actual SDK, we can cherrypick and release that change if it's important to do that now?

This comment has been minimized.

Copy link
@RReverser

RReverser Aug 30, 2024

Author Member

we can cherrypick and release that change if it's important to do that now?

Yeah that's exactly what I suggested above.

Basically, those docs should have been updated during Protobufectomy, but they weren't so instead doc update was committed as a follow-up.

Since we don't want to release all the functional changes after master yet, we should at least cherry-pick the docs and the scripts.

This comment has been minimized.

Copy link
@bfops

bfops Aug 30, 2024

Author Collaborator

we can cherrypick and release that change if it's important to do that now?

Yeah that's exactly what I suggested above.

Basically, those docs should have been updated during Protobufectomy, but they weren't so instead doc update was committed as a follow-up.

Since we don't want to release all the functional changes after master yet, we should at least cherry-pick the docs and the scripts.

oops sorry! I'm bad at reading. Yeah I can do that 👍

This comment has been minimized.

Copy link
@bfops

bfops Aug 30, 2024

Author Collaborator
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 732dd28

Please sign in to comment.