Skip to content

Commit

Permalink
Update DEVELOP.md to reflect new codegen (#119) (#125)
Browse files Browse the repository at this point in the history
## Description of Changes
#123 reverted the non-code-changes in #119. This cherrypicks them back.

See the discussion at
732dd28#r146042766
for more context.

Co-authored-by: Jeremie Pelletier <[email protected]>
  • Loading branch information
bfops and lcodes authored Aug 30, 2024
1 parent 32e43ca commit d46057c
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 53 deletions.
17 changes: 3 additions & 14 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# Notes for maintainers

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

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 `/`.
To regenerate this namespace, run the `tools~/gen-client-api.sh` or the
`tools~/gen-client-api.bat` script.
5 changes: 2 additions & 3 deletions src/SpacetimeDB/ClientApi/CallReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

namespace SpacetimeDB.ClientApi
{
[DataContract]
[SpacetimeDB.Type]
[DataContract]
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: 1 addition & 0 deletions src/SpacetimeDB/ClientApi/ClientMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable enable

using System;
using SpacetimeDB;

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

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

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

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

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

namespace SpacetimeDB.ClientApi
{
[DataContract]
[SpacetimeDB.Type]
[DataContract]
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: 2 additions & 3 deletions src/SpacetimeDB/ClientApi/InitialSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

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

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

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

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

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

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

public System.Collections.Generic.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
{
[DataContract]
[SpacetimeDB.Type]
[DataContract]
public partial class OneOffTable
{
[DataMember(Name = "table_name")]
public string TableName = "";

[DataMember(Name = "rows")]
public List<SpacetimeDB.ClientApi.EncodedValue> Rows = new();
public System.Collections.Generic.List<SpacetimeDB.ClientApi.EncodedValue> Rows = new();

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

namespace SpacetimeDB.ClientApi
{
[DataContract]
[SpacetimeDB.Type]
[DataContract]
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: 1 addition & 0 deletions src/SpacetimeDB/ClientApi/ServerMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#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
{
[DataContract]
[SpacetimeDB.Type]
[DataContract]
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: 4 additions & 6 deletions src/SpacetimeDB/ClientApi/TableUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@

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

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

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

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

}
}
7 changes: 1 addition & 6 deletions src/SpacetimeDB/ClientApi/TransactionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@ 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;

}
}
20 changes: 20 additions & 0 deletions tools~/gen-client-api.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
setlocal

if "%CL_HOME%"=="" (
echo "Variable CL_HOME not set"
exit /b 1
)

cd %CL_HOME%\SpacetimeDB\crates\client-api-messages
cargo run --example get_ws_schema > %CL_HOME%/schema.json

cd %CL_HOME%\SpacetimeDB\crates\cli
cargo run -- generate -l csharp -n SpacetimeDB.ClientApi ^
--json-module %CL_HOME%\schema.json ^
-o %CL_HOME%\spacetimedb-csharp-sdk\src\SpacetimeDB\ClientApi

cd %CL_HOME%\spacetimedb-csharp-sdk\src\SpacetimeDB\ClientApi
del /q _Globals

del %CL_HOME%\schema.json
15 changes: 15 additions & 0 deletions tools~/gen-client-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh -eu
: $CL_HOME

cd $CL_HOME/SpacetimeDB/crates/client-api-messages
cargo run --example get_ws_schema > $CL_HOME/schema.json

cd $CL_HOME/SpacetimeDB/crates/cli
cargo run -- generate -l csharp -n SpacetimeDB.ClientApi \
--json-module $CL_HOME/schema.json \
-o $CL_HOME/spacetimedb-csharp-sdk/src/SpacetimeDB/ClientApi

cd $CL_HOME/spacetimedb-csharp-sdk/src/SpacetimeDB/ClientApi
rm -rf _Globals

rm -f $CL_HOME/schema.json

0 comments on commit d46057c

Please sign in to comment.