Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions crates/bindings-csharp/Codegen.Tests/fixtures/diag/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,33 +437,33 @@ public MyStruct(int x)
}

[SpacetimeDB.Table]
[SpacetimeDB.Index.BTree(Name = "TestIndexWithoutColumns")]
[SpacetimeDB.Index.BTree(Name = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Name = "TestUnknownColumns", Columns = ["UnknownColumn"])]
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithoutColumns")]
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Accessor = "TestUnknownColumns", Columns = ["UnknownColumn"])]
public partial struct TestIndexIssues
{
[SpacetimeDB.Index.BTree(Name = "TestUnexpectedColumns", Columns = ["UnexpectedColumn"])]
[SpacetimeDB.Index.BTree(Accessor = "TestUnexpectedColumns", Columns = ["UnexpectedColumn"])]
public int SelfIndexingColumn;
}

[SpacetimeDB.Table(
Name = "TestScheduleWithoutPrimaryKey",
Accessor = "TestScheduleWithoutPrimaryKey",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtCorrectType)
)]
[SpacetimeDB.Table(
Name = "TestScheduleWithWrongPrimaryKeyType",
Accessor = "TestScheduleWithWrongPrimaryKeyType",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtCorrectType)
)]
[SpacetimeDB.Table(Name = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(Accessor = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(
Name = "TestScheduleWithWrongScheduleAtType",
Accessor = "TestScheduleWithWrongScheduleAtType",
Scheduled = "DummyScheduledReducer",
ScheduledAt = nameof(ScheduleAtWrongType)
)]
[SpacetimeDB.Table(
Name = "TestScheduleWithMissingScheduleAtField",
Accessor = "TestScheduleWithMissingScheduleAtField",
Scheduled = "DummyScheduledReducer",
ScheduledAt = "MissingField"
)]
Expand Down Expand Up @@ -517,36 +517,36 @@ public partial class Module
);

// Invalid: View definition missing Public=true
[SpacetimeDB.View(Name = "view_def_no_public")]
[SpacetimeDB.View(Accessor = "view_def_no_public")]
public static List<Player> ViewDefNoPublic(ViewContext ctx)
{
return new List<Player>();
}

// Invalid: View definition with missing context type
[SpacetimeDB.View(Name = "view_def_no_context", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_no_context", Public = true)]
public static List<Player> ViewDefNoContext()
{
return new List<Player>();
}

// Invalid: View definition with wrong context type
[SpacetimeDB.View(Name = "view_def_wrong_context", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_wrong_context", Public = true)]
public static List<Player> ViewDefWrongContext(ReducerContext ctx)
{
return new List<Player>();
}

// Invalid: View that performs Insert
[SpacetimeDB.View(Name = "view_no_insert", Public = true)]
[SpacetimeDB.View(Accessor = "view_no_insert", Public = true)]
public static Player? ViewNoInsert(ViewContext ctx)
{
ctx.Db.Player.Insert(new Player { Identity = new() });
return new Player { Identity = new() };
}

// Invalid: View that performs Delete
[SpacetimeDB.View(Name = "view_no_delete", Public = true)]
[SpacetimeDB.View(Accessor = "view_no_delete", Public = true)]
public static Player? ViewNoDelete(ViewContext ctx)
{
ctx.Db.Player.Delete(new Player { Identity = new() });
Expand All @@ -555,41 +555,41 @@ public static List<Player> ViewDefWrongContext(ReducerContext ctx)

// TODO: Investigate why void return breaks the FFI generation
// // Invalid: Void return type is not Vec<T> or Option<T>
// [SpacetimeDB.View(Name = "view_def_no_return", Public = true)]
// [SpacetimeDB.View(Accessor = "view_def_no_return", Public = true)]
// public static void ViewDefNoReturn(ViewContext ctx)
// {
// return;
// }

// Invalid: Wrong return type is not Vec<T> or Option<T>
[SpacetimeDB.View(Name = "view_def_wrong_return", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_wrong_return", Public = true)]
public static Player ViewDefWrongReturn(ViewContext ctx)
{
return new Player { Identity = new() };
}

// Invalid: Returns type that is not a SpacetimeType
[SpacetimeDB.View(Name = "view_def_returns_not_a_spacetime_type", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_returns_not_a_spacetime_type", Public = true)]
public static NotSpacetimeType? ViewDefReturnsNotASpacetimeType(AnonymousViewContext ctx)
{
return new NotSpacetimeType();
}

[SpacetimeDB.View(Name = "view_def_no_anon_identity", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_no_anon_identity", Public = true)]
public static Player? ViewDefNoAnonIdentity(AnonymousViewContext ctx)
{
ctx.GetIdentity();
return null;
}

[SpacetimeDB.View(Name = "view_def_no_iter", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_no_iter", Public = true)]
public static Player? ViewDefNoIter(AnonymousViewContext ctx)
{
ctx.Db.Player.Iter();
return null;
}

[SpacetimeDB.View(Name = "view_def_index_no_mutation", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_index_no_mutation", Public = true)]
public static Player? ViewDefIndexNoMutation(AnonymousViewContext ctx)
{
ctx.Db.Player.Identity.Delete(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public partial record TestTableTaggedEnum : SpacetimeDB.TaggedEnum<(int X, int Y
},
{/*
{
[SpacetimeDB.Index.BTree(Name = "TestUnexpectedColumns", Columns = ["UnexpectedColumn"])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Accessor = "TestUnexpectedColumns", Columns = ["UnexpectedColumn"])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
public int SelfIndexingColumn;
*/
Message: Index attribute on a field applies directly to that field, so it doesn't accept the Columns parameter.,
Expand All @@ -104,9 +104,9 @@ public partial record TestTableTaggedEnum : SpacetimeDB.TaggedEnum<(int X, int Y
},
{/*
[SpacetimeDB.Table]
[SpacetimeDB.Index.BTree(Name = "TestIndexWithoutColumns")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Name = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithoutColumns")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithEmptyColumns", Columns = [])]
*/
Message: Index attribute doesn't specify columns.,
Severity: Error,
Expand All @@ -120,10 +120,10 @@ public partial record TestTableTaggedEnum : SpacetimeDB.TaggedEnum<(int X, int Y
}
},
{/*
[SpacetimeDB.Index.BTree(Name = "TestIndexWithoutColumns")]
[SpacetimeDB.Index.BTree(Name = "TestIndexWithEmptyColumns", Columns = [])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Name = "TestUnknownColumns", Columns = ["UnknownColumn"])]
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithoutColumns")]
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithEmptyColumns", Columns = [])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Accessor = "TestUnknownColumns", Columns = ["UnknownColumn"])]
*/
Message: Index attribute doesn't specify columns.,
Severity: Error,
Expand All @@ -137,9 +137,9 @@ public partial record TestTableTaggedEnum : SpacetimeDB.TaggedEnum<(int X, int Y
}
},
{/*
[SpacetimeDB.Index.BTree(Name = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Name = "TestUnknownColumns", Columns = ["UnknownColumn"])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Index.BTree(Accessor = "TestIndexWithEmptyColumns", Columns = [])]
[SpacetimeDB.Index.BTree(Accessor = "TestUnknownColumns", Columns = ["UnknownColumn"])]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
public partial struct TestIndexIssues
*/
Message: Could not find the specified column UnknownColumn in TestIndexIssues.,
Expand All @@ -157,8 +157,8 @@ public partial struct TestIndexIssues

[SpacetimeDB.Table(
^^^^^^^^^^^^^^^^^^
Name = "TestScheduleWithoutPrimaryKey",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Accessor = "TestScheduleWithoutPrimaryKey",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Scheduled = "DummyScheduledReducer",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ScheduledAt = nameof(ScheduleAtCorrectType)
Expand All @@ -182,15 +182,15 @@ public partial struct TestIndexIssues
)]
[SpacetimeDB.Table(
^^^^^^^^^^^^^^^^^^
Name = "TestScheduleWithWrongPrimaryKeyType",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Accessor = "TestScheduleWithWrongPrimaryKeyType",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Scheduled = "DummyScheduledReducer",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ScheduledAt = nameof(ScheduleAtCorrectType)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)]
^
[SpacetimeDB.Table(Name = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(Accessor = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
*/
Message: TestScheduleWithWrongPrimaryKeyType is a scheduled table but doesn't have a primary key of type `ulong`.,
Severity: Error,
Expand All @@ -205,8 +205,8 @@ public partial struct TestIndexIssues
},
{/*
)]
[SpacetimeDB.Table(Name = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Table(Accessor = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.Table(
*/
Message: Could not find the specified column ScheduledAt in TestScheduleIssues.,
Expand All @@ -221,11 +221,11 @@ public partial struct TestIndexIssues
}
},
{/*
[SpacetimeDB.Table(Name = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(Accessor = "TestScheduleWithoutScheduleAt", Scheduled = "DummyScheduledReducer")]
[SpacetimeDB.Table(
^^^^^^^^^^^^^^^^^^
Name = "TestScheduleWithWrongScheduleAtType",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Accessor = "TestScheduleWithWrongScheduleAtType",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Scheduled = "DummyScheduledReducer",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ScheduledAt = nameof(ScheduleAtWrongType)
Expand All @@ -249,8 +249,8 @@ public partial struct TestIndexIssues
)]
[SpacetimeDB.Table(
^^^^^^^^^^^^^^^^^^
Name = "TestScheduleWithMissingScheduleAtField",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Accessor = "TestScheduleWithMissingScheduleAtField",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Scheduled = "DummyScheduledReducer",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ScheduledAt = "MissingField"
Expand All @@ -272,8 +272,8 @@ public partial struct TestScheduleIssues
},
{/*
// Invalid: View definition missing Public=true
[SpacetimeDB.View(Name = "view_def_no_public")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.View(Accessor = "view_def_no_public")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
public static List<Player> ViewDefNoPublic(ViewContext ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{
Expand All @@ -296,7 +296,7 @@ public partial struct TestScheduleIssues
}
},
{/*
[SpacetimeDB.View(Name = "view_def_no_context", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_no_context", Public = true)]
public static List<Player> ViewDefNoContext()
^^
{
Expand All @@ -313,7 +313,7 @@ public partial struct TestScheduleIssues
}
},
{/*
[SpacetimeDB.View(Name = "view_def_wrong_context", Public = true)]
[SpacetimeDB.View(Accessor = "view_def_wrong_context", Public = true)]
public static List<Player> ViewDefWrongContext(ReducerContext ctx)
^^^^^^^^^^^^^^^^^^^^
{
Expand All @@ -331,8 +331,8 @@ public partial struct TestScheduleIssues
},
{/*
// Invalid: Wrong return type is not Vec<T> or Option<T>
[SpacetimeDB.View(Name = "view_def_wrong_return", Public = true)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[SpacetimeDB.View(Accessor = "view_def_wrong_return", Public = true)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
public static Player ViewDefWrongReturn(ViewContext ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{
Expand Down
14 changes: 7 additions & 7 deletions crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public static void Init(ReducerContext ctx)
}
}

[SpacetimeDB.Table(Name = "MultiTable1", Public = true)]
[SpacetimeDB.Table(Name = "MultiTable2")]
[SpacetimeDB.Table(Accessor = "MultiTable1", Public = true)]
[SpacetimeDB.Table(Accessor = "MultiTable2")]
public partial struct MultiTableRow
{
[SpacetimeDB.Index.BTree(Table = "MultiTable1")]
Expand All @@ -226,7 +226,7 @@ public static void InsertMultiData(ReducerContext ctx, MultiTableRow data)
}

[SpacetimeDB.Table]
[SpacetimeDB.Index.BTree(Name = "Location", Columns = ["X", "Y", "Z"])]
[SpacetimeDB.Index.BTree(Accessor = "Location", Columns = ["X", "Y", "Z"])]
partial struct BTreeMultiColumn
{
public uint X;
Expand All @@ -235,7 +235,7 @@ partial struct BTreeMultiColumn
}

[SpacetimeDB.Table]
[SpacetimeDB.Index.BTree(Name = "Location", Columns = ["X", "Y"])]
[SpacetimeDB.Index.BTree(Accessor = "Location", Columns = ["X", "Y"])]
partial struct BTreeViews
{
[SpacetimeDB.PrimaryKey]
Expand Down Expand Up @@ -274,19 +274,19 @@ public class Module
[SpacetimeDB.ClientVisibilityFilter]
public static readonly Filter ALL_PUBLIC_TABLES = new Filter.Sql("SELECT * FROM PublicTable");

[SpacetimeDB.View(Name = "public_table_view", Public = true)]
[SpacetimeDB.View(Accessor = "public_table_view", Public = true)]
public static PublicTable? PublicTableByIdentity(ViewContext ctx)
{
return (PublicTable?)ctx.Db.PublicTable.Id.Find(0);
}

[SpacetimeDB.View(Name = "public_table_query", Public = true)]
[SpacetimeDB.View(Accessor = "public_table_query", Public = true)]
public static Query<PublicTable> PublicTableQuery(ViewContext ctx)
{
return ctx.From.PublicTable().Where(cols => cols.Id.Eq(0)).Build();
}

[SpacetimeDB.View(Name = "find_public_table__by_identity", Public = true)]
[SpacetimeDB.View(Accessor = "find_public_table__by_identity", Public = true)]
public static PublicTable? FindPublicTableByIdentity(AnonymousViewContext ctx)
{
return (PublicTable?)ctx.Db.PublicTable.Id.Find(0);
Expand Down
8 changes: 4 additions & 4 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public TableAccessor(TableDeclaration table, AttributeData data, DiagReporter di
{
var attr = data.ParseAs<TableAttribute>();

Name = attr.Name ?? table.ShortName;
Name = attr.Accessor ?? table.ShortName;
IsPublic = attr.Public;
IsEvent = attr.Event;
if (
Expand Down Expand Up @@ -318,7 +318,7 @@ public TableIndex(ColumnRef col)
/// Used internally by other constructors that parse attributes.
/// </summary>
private TableIndex(Index.BTreeAttribute attr, ImmutableArray<ColumnRef> columns)
: this(attr.Name, columns, attr.Table, TableIndexType.BTree) { }
: this(attr.Accessor, columns, attr.Table, TableIndexType.BTree) { }

/// <summary>
/// Creates an index from a table declaration and attribute data.
Expand Down Expand Up @@ -1068,7 +1068,7 @@ public ViewDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter dia
var isAnonymousContext = firstParamType?.Name == "AnonymousViewContext";
var hasArguments = method.Parameters.Length > 1;

if (string.IsNullOrEmpty(attr.Name))
if (string.IsNullOrEmpty(attr.Accessor))
{
diag.Report(ErrorDescriptor.ViewMustHaveName, methodSyntax);
}
Expand All @@ -1082,7 +1082,7 @@ public ViewDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter dia
diag.Report(ErrorDescriptor.ViewArgsUnsupported, methodSyntax);
}

Name = attr.Name ?? method.Name;
Name = attr.Accessor ?? method.Name;
FullName = SymbolToName(method);
IsPublic = attr.Public;
IsAnonymous = isAnonymousContext;
Expand Down
Loading
Loading