Skip to content

Commit 29da61e

Browse files
Merge remote-tracking branch 'origin/master' into shub/table-name-to-accessor
# Conflicts: # demo/Blackholio/client-unity/Assets/Scripts/autogen/SpacetimeDBClient.g.cs
2 parents 55dfedf + 15b7480 commit 29da61e

106 files changed

Lines changed: 1432 additions & 2136 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ new.json
225225
*.pem
226226
.ok.sql
227227

228+
# Intermediate file generated when updating the external client SDKs' WS format bindings
229+
crates/client-api-messages/ws_schema.json
230+
228231
# Test data
229232
!crates/core/testdata/
230233

crates/codegen/src/csharp.rs

Lines changed: 15 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use spacetimedb_schema::type_for_generate::{
2525
const INDENT: &str = " ";
2626

2727
const REDUCER_EVENTS: &str = r#"
28-
public interface IRemoteDbContext : IDbContext<RemoteTables, RemoteReducers, SetReducerFlags, SubscriptionBuilder, RemoteProcedures> {
28+
public interface IRemoteDbContext : IDbContext<RemoteTables, RemoteReducers, SubscriptionBuilder, RemoteProcedures> {
2929
public event Action<ReducerEventContext, Exception>? OnUnhandledReducerError;
3030
}
3131
@@ -52,14 +52,6 @@ const REDUCER_EVENTS: &str = r#"
5252
/// </summary>
5353
public RemoteReducers Reducers => conn.Reducers;
5454
/// <summary>
55-
/// Access to setters for per-reducer flags.
56-
///
57-
/// The returned <c>SetReducerFlags</c> will have a method to invoke,
58-
/// for each reducer defined by the module,
59-
/// which call-flags for the reducer can be set.
60-
/// </summary>
61-
public SetReducerFlags SetReducerFlags => conn.SetReducerFlags;
62-
/// <summary>
6355
/// Access to procedures defined by the module.
6456
///
6557
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
@@ -132,14 +124,6 @@ const REDUCER_EVENTS: &str = r#"
132124
/// </summary>
133125
public RemoteReducers Reducers => conn.Reducers;
134126
/// <summary>
135-
/// Access to setters for per-reducer flags.
136-
///
137-
/// The returned <c>SetReducerFlags</c> will have a method to invoke,
138-
/// for each reducer defined by the module,
139-
/// which call-flags for the reducer can be set.
140-
/// </summary>
141-
public SetReducerFlags SetReducerFlags => conn.SetReducerFlags;
142-
/// <summary>
143127
/// Access to procedures defined by the module.
144128
///
145129
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
@@ -217,14 +201,6 @@ const REDUCER_EVENTS: &str = r#"
217201
/// </summary>
218202
public RemoteReducers Reducers => conn.Reducers;
219203
/// <summary>
220-
/// Access to setters for per-reducer flags.
221-
///
222-
/// The returned <c>SetReducerFlags</c> will have a method to invoke,
223-
/// for each reducer defined by the module,
224-
/// which call-flags for the reducer can be set.
225-
/// </summary>
226-
public SetReducerFlags SetReducerFlags => conn.SetReducerFlags;
227-
/// <summary>
228204
/// Access to procedures defined by the module.
229205
///
230206
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
@@ -293,14 +269,6 @@ const REDUCER_EVENTS: &str = r#"
293269
/// </summary>
294270
public RemoteReducers Reducers => conn.Reducers;
295271
/// <summary>
296-
/// Access to setters for per-reducer flags.
297-
///
298-
/// The returned <c>SetReducerFlags</c> will have a method to invoke,
299-
/// for each reducer defined by the module,
300-
/// which call-flags for the reducer can be set.
301-
/// </summary>
302-
public SetReducerFlags SetReducerFlags => conn.SetReducerFlags;
303-
/// <summary>
304272
/// Access to procedures defined by the module.
305273
///
306274
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
@@ -372,14 +340,6 @@ const REDUCER_EVENTS: &str = r#"
372340
/// </summary>
373341
public RemoteReducers Reducers => conn.Reducers;
374342
/// <summary>
375-
/// Access to setters for per-reducer flags.
376-
///
377-
/// The returned <c>SetReducerFlags</c> will have a method to invoke,
378-
/// for each reducer defined by the module,
379-
/// which call-flags for the reducer can be set.
380-
/// </summary>
381-
public SetReducerFlags SetReducerFlags => conn.SetReducerFlags;
382-
/// <summary>
383343
/// Access to procedures defined by the module.
384344
///
385345
/// The returned <c>RemoteProcedures</c> will have a method to invoke each procedure defined by the module,
@@ -520,25 +480,11 @@ const REDUCER_EVENTS: &str = r#"
520480
/// or vice versa, may misbehave in any number of ways,
521481
/// including dropping subscriptions, corrupting the client cache, or panicking.
522482
/// </summary>
523-
public void SubscribeToAllTables()
524-
{
525-
// Make sure we use the legacy handle constructor here, even though there's only 1 query.
526-
// We drop the error handler, since it can't be called for legacy subscriptions.
527-
new SubscriptionHandle(
528-
conn,
529-
Applied,
530-
new string[] { "SELECT * FROM *" }
531-
);
532-
}
483+
public SubscriptionHandle SubscribeToAllTables() =>
484+
new(conn, Applied, Error, QueryBuilder.AllTablesSqlQueries());
533485
}
534486
535487
public sealed class SubscriptionHandle : SubscriptionHandleBase<SubscriptionEventContext, ErrorContext> {
536-
/// <summary>
537-
/// Internal API. Construct <c>SubscriptionHandle</c>s using <c>conn.SubscriptionBuilder</c>.
538-
/// </summary>
539-
public SubscriptionHandle(IDbConnection conn, Action<SubscriptionEventContext>? onApplied, string[] querySqls) : base(conn, onApplied, querySqls)
540-
{ }
541-
542488
/// <summary>
543489
/// Internal API. Construct <c>SubscriptionHandle</c>s using <c>conn.SubscriptionBuilder</c>.
544490
/// </summary>
@@ -830,7 +776,7 @@ impl Lang for Csharp<'_> {
830776
indented_block(output, |output| {
831777
writeln!(
832778
output,
833-
"conn.InternalCallReducer(new Reducer.{func_name_pascal_case}({func_args}), this.SetCallReducerFlags.{func_name_pascal_case}Flags);"
779+
"conn.InternalCallReducer(new Reducer.{func_name_pascal_case}({func_args}));"
834780
);
835781
});
836782
writeln!(output);
@@ -890,16 +836,6 @@ impl Lang for Csharp<'_> {
890836
);
891837
});
892838

893-
if is_reducer_invokable(reducer) {
894-
writeln!(output);
895-
writeln!(output, "public sealed partial class SetReducerFlags");
896-
indented_block(&mut output, |output| {
897-
let func_name_pascal_case = reducer.name.deref().to_case(Case::Pascal);
898-
writeln!(output, "internal CallReducerFlags {func_name_pascal_case}Flags;");
899-
writeln!(output, "public void {func_name_pascal_case}(CallReducerFlags flags) => {func_name_pascal_case}Flags = flags;");
900-
});
901-
}
902-
903839
OutputFile {
904840
filename: format!("Reducers/{}.g.cs", reducer.name.deref().to_case(Case::Pascal)),
905841
code: output.into_inner(),
@@ -1023,11 +959,7 @@ impl Lang for Csharp<'_> {
1023959

1024960
writeln!(output, "public sealed partial class RemoteReducers : RemoteBase");
1025961
indented_block(&mut output, |output| {
1026-
writeln!(
1027-
output,
1028-
"internal RemoteReducers(DbConnection conn, SetReducerFlags flags) : base(conn) => SetCallReducerFlags = flags;"
1029-
);
1030-
writeln!(output, "internal readonly SetReducerFlags SetCallReducerFlags;");
962+
writeln!(output, "internal RemoteReducers(DbConnection conn) : base(conn) {{ }}");
1031963
writeln!(
1032964
output,
1033965
"internal event Action<ReducerEventContext, Exception>? InternalOnUnhandledReducerError;"
@@ -1059,13 +991,20 @@ impl Lang for Csharp<'_> {
1059991
});
1060992
writeln!(output);
1061993

1062-
writeln!(output, "public sealed partial class SetReducerFlags {{ }}");
1063-
1064994
writeln!(output, "{REDUCER_EVENTS}");
1065995

1066996
writeln!(output, "public sealed class QueryBuilder");
1067997
indented_block(&mut output, |output| {
1068998
writeln!(output, "public From From {{ get; }} = new();");
999+
writeln!(output);
1000+
writeln!(output, "internal static string[] AllTablesSqlQueries() => new string[]");
1001+
indented_block(output, |output| {
1002+
for (table_name, _) in iter_table_names_and_types(module, options.visibility) {
1003+
let method_name = table_name.deref().to_case(Case::Pascal);
1004+
writeln!(output, "new QueryBuilder().From.{method_name}().ToSql(),");
1005+
}
1006+
});
1007+
writeln!(output, ";");
10691008
});
10701009
writeln!(output);
10711010

@@ -1158,45 +1097,17 @@ impl Lang for Csharp<'_> {
11581097
indented_block(&mut output, |output: &mut CodeIndenter<String>| {
11591098
writeln!(output, "public override RemoteTables Db {{ get; }}");
11601099
writeln!(output, "public readonly RemoteReducers Reducers;");
1161-
writeln!(output, "public readonly SetReducerFlags SetReducerFlags = new();");
11621100
writeln!(output, "public readonly RemoteProcedures Procedures;");
11631101
writeln!(output);
11641102

11651103
writeln!(output, "public DbConnection()");
11661104
indented_block(output, |output| {
11671105
writeln!(output, "Db = new(this);");
1168-
writeln!(output, "Reducers = new(this, SetReducerFlags);");
1106+
writeln!(output, "Reducers = new(this);");
11691107
writeln!(output, "Procedures = new(this);");
11701108
});
11711109
writeln!(output);
11721110

1173-
writeln!(output, "protected override Reducer ToReducer(TransactionUpdate update)");
1174-
indented_block(output, |output| {
1175-
writeln!(output, "var encodedArgs = update.ReducerCall.Args;");
1176-
writeln!(output, "return update.ReducerCall.ReducerName switch {{");
1177-
{
1178-
indent_scope!(output);
1179-
for reducer in iter_reducers(module, options.visibility) {
1180-
let reducer_str_name = &reducer.name;
1181-
let reducer_name = reducer.name.deref().to_case(Case::Pascal);
1182-
writeln!(
1183-
output,
1184-
"\"{reducer_str_name}\" => BSATNHelpers.Decode<Reducer.{reducer_name}>(encodedArgs),"
1185-
);
1186-
}
1187-
writeln!(
1188-
output,
1189-
r#""" => throw new SpacetimeDBEmptyReducerNameException("Reducer name is empty"),"#
1190-
);
1191-
writeln!(
1192-
output,
1193-
r#"var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {{reducer}}")"#
1194-
);
1195-
}
1196-
writeln!(output, "}};");
1197-
});
1198-
writeln!(output);
1199-
12001111
writeln!(
12011112
output,
12021113
"protected override IEventContext ToEventContext(Event<Reducer> Event) =>"

0 commit comments

Comments
 (0)