@@ -1156,7 +1156,7 @@ pub fn autogen_typescript_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String
11561156 writeln ! ( output) . unwrap ( ) ;
11571157
11581158 writeln ! ( output, "// @ts-ignore" ) . unwrap ( ) ;
1159- writeln ! ( output, "import {{ __SPACETIMEDB__, AlgebraicType, ProductType, BuiltinType, ProductTypeElement, IDatabaseTable, AlgebraicValue, ReducerArgsAdapter, SumTypeVariant }} from \" @clockworklabs/spacetimedb-sdk\" ;" ) . unwrap ( ) ;
1159+ writeln ! ( output, "import {{ __SPACETIMEDB__, AlgebraicType, ProductType, BuiltinType, ProductTypeElement, IDatabaseTable, AlgebraicValue, ReducerArgsAdapter, SumTypeVariant, Serializer }} from \" @clockworklabs/spacetimedb-sdk\" ;" ) . unwrap ( ) ;
11601160
11611161 let mut imports = Vec :: new ( ) ;
11621162 generate_imports (
@@ -1201,8 +1201,28 @@ pub fn autogen_typescript_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String
12011201 writeln ! ( output, "if (__SPACETIMEDB__.spacetimeDBClient) {{" ) . unwrap ( ) ;
12021202 writeln ! (
12031203 output,
1204- "\t __SPACETIMEDB__.spacetimeDBClient.call(\" {func_name}\" , [{}]);" ,
1205- arg_names. join( ", " )
1204+ "const serializer = __SPACETIMEDB__.spacetimeDBClient.getSerializer();"
1205+ )
1206+ . unwrap ( ) ;
1207+
1208+ let mut arg_names = Vec :: new ( ) ;
1209+ for arg in reducer. args . iter ( ) {
1210+ let ty = & arg. algebraic_type ;
1211+ let name = arg
1212+ . name
1213+ . as_deref ( )
1214+ . unwrap_or_else ( || panic ! ( "reducer args should have names: {func_name}" ) ) ;
1215+ let arg_name = name. to_case ( Case :: Camel ) ;
1216+
1217+ writeln ! ( output, "let _{arg_name}Type = {};" , convert_algebraic_type( ctx, ty, "" ) ) . unwrap ( ) ;
1218+ writeln ! ( output, "serializer.write(_{arg_name}Type, _{arg_name});" ) . unwrap ( ) ;
1219+
1220+ arg_names. push ( arg_name) ;
1221+ }
1222+
1223+ writeln ! (
1224+ output,
1225+ "\t __SPACETIMEDB__.spacetimeDBClient.call(\" {func_name}\" , serializer);"
12061226 )
12071227 . unwrap ( ) ;
12081228 writeln ! ( output, "}}" ) . unwrap ( ) ;
0 commit comments