SpacetimeDB
SpacetimeDB copied to clipboard
Bug on generated typescript from c# module
While following the guide in the docs for c# server and typescript client i got problems getting all the users in the client.
The problem was in the typescript generated code.
Table in c# server module
[Table(Name = "user", Public = true)]
public partial class User
{
[PrimaryKey]
public Identity Identity;
public string? Name;
public bool Online;
}
Table type generated, identity is in lower case.
export type User = {
identity: Identity,
name: string | undefined,
online: boolean,
};
...
export function getTypeScriptAlgebraicType(): AlgebraicType {
return AlgebraicType.createProductType([
new ProductTypeElement("identity", AlgebraicType.createIdentityType()),
new ProductTypeElement("name", AlgebraicType.createOptionType(AlgebraicType.createStringType())),
new ProductTypeElement("online", AlgebraicType.createBoolType()),
]);
}
...
primaryKey in REMOTE_MODULE has Identity
const REMOTE_MODULE = {
tables: {
user: {
tableName: "user",
rowType: User.getTypeScriptAlgebraicType(),
primaryKey: "Identity",
},
},
...
}
Because the primaryKey was in the wrong case when processing the messages received from the server, in the applyOperations it will result in only one insert where the key in the insertMap is undefined.
> spacetime --version
spacetime Path: C:\Users\****\AppData\Local\SpacetimeDB\bin\current\spacetimedb-cli.exe
Commit: 4032a44686c41828ead7f59eac871c34267d4572
spacetimedb tool version 1.0.0; spacetimedb-lib version 1.0.0;
Thanks for reporting! I believe this will be fixed by #2409.