diff --git a/crates/cli/src/subcommands/generate/typescript.rs b/crates/cli/src/subcommands/generate/typescript.rs index edab098d36..08ca49178a 100644 --- a/crates/cli/src/subcommands/generate/typescript.rs +++ b/crates/cli/src/subcommands/generate/typescript.rs @@ -203,7 +203,7 @@ export class {table_handle} {{ out.with_indent(|out| { writeln!(out, "for (let row of this.tableCache.iter()) {{"); out.with_indent(|out| { - writeln!(out, "if (row.{unique_field_name} === col_val) {{"); + writeln!(out, "if (deepEqual(row.{unique_field_name}, col_val)) {{"); out.with_indent(|out| { writeln!(out, "return row;"); }); @@ -350,7 +350,7 @@ Requested namespace: {namespace}", writeln!(out, "{}: {{", table.name); out.indent(1); writeln!(out, "tableName: \"{}\",", table.name); - writeln!(out, "rowType: {row_type}.getAlgebraicType(),"); + writeln!(out, "rowType: {row_type}.getTypeScriptAlgebraicType(),"); if let Some(pk) = schema.pk() { writeln!(out, "primaryKey: \"{}\",", pk.col_name); } @@ -367,7 +367,7 @@ Requested namespace: {namespace}", writeln!(out, "reducerName: \"{}\",", reducer.name); writeln!( out, - "argsType: {args_type}.getAlgebraicType(),", + "argsType: {args_type}.getTypeScriptAlgebraicType(),", args_type = reducer_args_type_name(&reducer.name) ); out.dedent(1); @@ -463,7 +463,10 @@ fn print_remote_reducers(module: &ModuleDef, out: &mut Indenter) { out.with_indent(|out| { writeln!(out, "const __args = {{ {arg_name_list} }};"); writeln!(out, "let __writer = new BinaryWriter(1024);"); - writeln!(out, "{reducer_variant}.getAlgebraicType().serialize(__writer, __args);"); + writeln!( + out, + "{reducer_variant}.getTypeScriptAlgebraicType().serialize(__writer, __args);" + ); writeln!(out, "let __argsBuffer = __writer.getBuffer();"); writeln!(out, "this.connection.callReducer(\"{reducer_name}\", __argsBuffer);"); }); @@ -513,10 +516,12 @@ fn print_remote_tables(module: &ModuleDef, out: &mut Indenter) { let table_handle = table_name_pascalcase.clone() + "TableHandle"; let type_ref = table.product_type_ref; let row_type = type_ref_name(module, type_ref); - writeln!(out, "#{table_name_camelcase} = this.connection.clientCache.getOrCreateTable<{row_type}>(REMOTE_MODULE.tables.{table_name});"); writeln!(out, "get {table_name_camelcase}(): {table_handle} {{"); out.with_indent(|out| { - writeln!(out, "return new {table_handle}(this.#{table_name_camelcase});"); + writeln!( + out, + "return new {table_handle}(this.connection.clientCache.getOrCreateTable<{row_type}>(REMOTE_MODULE.tables.{table_name}));" + ); }); writeln!(out, "}}"); } @@ -575,6 +580,7 @@ fn print_spacetimedb_imports(out: &mut Indenter) { "DBConnectionImpl", "DBContext", "Event", + "deepEqual", ]; types.sort(); writeln!(out, "import {{"); @@ -604,7 +610,7 @@ fn write_get_algebraic_type_for_product( * This function is derived from the AlgebraicType used to generate this type. */" ); - writeln!(out, "export function getAlgebraicType(): AlgebraicType {{"); + writeln!(out, "export function getTypeScriptAlgebraicType(): AlgebraicType {{"); { out.indent(1); write!(out, "return "); @@ -648,30 +654,14 @@ fn define_namespace_and_object_type_for_product( "export function serialize(writer: BinaryWriter, value: {name}): void {{" ); out.indent(1); - writeln!(out, "const converted = {{"); - out.indent(1); - for (ident, _) in elements { - let name = ident.deref().to_case(Case::Camel); - writeln!(out, "{ident}: value.{name},"); - } - out.dedent(1); - writeln!(out, "}};"); - writeln!(out, "{name}.getAlgebraicType().serialize(writer, converted);"); + writeln!(out, "{name}.getTypeScriptAlgebraicType().serialize(writer, value);"); out.dedent(1); writeln!(out, "}}"); writeln!(out); writeln!(out, "export function deserialize(reader: BinaryReader): {name} {{"); out.indent(1); - writeln!(out, "const value = {name}.getAlgebraicType().deserialize(reader);"); - writeln!(out, "return {{"); - out.indent(1); - for (ident, _) in elements { - let name = ident.deref().to_case(Case::Camel); - writeln!(out, "{name}: value.{ident},"); - } - out.dedent(1); - writeln!(out, "}};"); + writeln!(out, "return {name}.getTypeScriptAlgebraicType().deserialize(reader);"); out.dedent(1); writeln!(out, "}}"); writeln!(out); @@ -783,7 +773,7 @@ fn write_get_algebraic_type_for_sum( out: &mut Indenter, variants: &[(Identifier, AlgebraicTypeUse)], ) { - writeln!(out, "export function getAlgebraicType(): AlgebraicType {{"); + writeln!(out, "export function getTypeScriptAlgebraicType(): AlgebraicType {{"); { indent_scope!(out); write!(out, "return "); @@ -833,7 +823,7 @@ fn define_namespace_and_types_for_sum( writeln!( out, "export function serialize(writer: BinaryWriter, value: {name}): void {{ - {name}.getAlgebraicType().serialize(writer, value); + {name}.getTypeScriptAlgebraicType().serialize(writer, value); }}" ); writeln!(out); @@ -841,7 +831,7 @@ fn define_namespace_and_types_for_sum( writeln!( out, "export function deserialize(reader: BinaryReader): {name} {{ - return {name}.getAlgebraicType().deserialize(reader); + return {name}.getTypeScriptAlgebraicType().deserialize(reader); }}" ); writeln!(out); @@ -980,7 +970,11 @@ fn convert_algebraic_type<'a>( convert_algebraic_type(module, out, ty, ref_prefix); write!(out, ")"); } - AlgebraicTypeUse::Ref(r) => write!(out, "{ref_prefix}{}.getAlgebraicType()", type_ref_name(module, *r)), + AlgebraicTypeUse::Ref(r) => write!( + out, + "{ref_prefix}{}.getTypeScriptAlgebraicType()", + type_ref_name(module, *r) + ), AlgebraicTypeUse::Primitive(prim) => { write!(out, "AlgebraicType.create{prim:?}Type()"); } @@ -1017,7 +1011,11 @@ fn convert_product_type<'a>( writeln!(out, "AlgebraicType.createProductType(["); out.indent(1); for (ident, ty) in elements { - write!(out, "new ProductTypeElement(\"{}\", ", ident.deref(),); + write!( + out, + "new ProductTypeElement(\"{}\", ", + ident.deref().to_case(Case::Camel) + ); convert_algebraic_type(module, out, ty, ref_prefix); writeln!(out, "),"); } diff --git a/crates/cli/tests/snapshots/codegen__codegen_typescript.snap b/crates/cli/tests/snapshots/codegen__codegen_typescript.snap index 28eae91d5d..9e60eae8f9 100644 --- a/crates/cli/tests/snapshots/codegen__codegen_typescript.snap +++ b/crates/cli/tests/snapshots/codegen__codegen_typescript.snap @@ -39,6 +39,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type AddPlayer = { @@ -53,24 +55,18 @@ export namespace AddPlayer { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("name", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: AddPlayer): void { - const converted = { - name: value.name, - }; - AddPlayer.getAlgebraicType().serialize(writer, converted); + AddPlayer.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): AddPlayer { - const value = AddPlayer.getAlgebraicType().deserialize(reader); - return { - name: value.name, - }; + return AddPlayer.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -113,6 +109,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type AddPrivate = { @@ -127,24 +125,18 @@ export namespace AddPrivate { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("name", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: AddPrivate): void { - const converted = { - name: value.name, - }; - AddPrivate.getAlgebraicType().serialize(writer, converted); + AddPrivate.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): AddPrivate { - const value = AddPrivate.getAlgebraicType().deserialize(reader); - return { - name: value.name, - }; + return AddPrivate.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -187,6 +179,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type Baz = { field: string, @@ -200,24 +194,18 @@ export namespace Baz { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("field", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: Baz): void { - const converted = { - field: value.field, - }; - Baz.getAlgebraicType().serialize(writer, converted); + Baz.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Baz { - const value = Baz.getAlgebraicType().deserialize(reader); - return { - field: value.field, - }; + return Baz.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -261,6 +249,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type DeletePlayer = { @@ -275,24 +265,18 @@ export namespace DeletePlayer { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("id", AlgebraicType.createU64Type()), ]); } export function serialize(writer: BinaryWriter, value: DeletePlayer): void { - const converted = { - id: value.id, - }; - DeletePlayer.getAlgebraicType().serialize(writer, converted); + DeletePlayer.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): DeletePlayer { - const value = DeletePlayer.getAlgebraicType().deserialize(reader); - return { - id: value.id, - }; + return DeletePlayer.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -335,6 +319,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type DeletePlayersByName = { @@ -349,24 +335,18 @@ export namespace DeletePlayersByName { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("name", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: DeletePlayersByName): void { - const converted = { - name: value.name, - }; - DeletePlayersByName.getAlgebraicType().serialize(writer, converted); + DeletePlayersByName.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): DeletePlayersByName { - const value = DeletePlayersByName.getAlgebraicType().deserialize(reader); - return { - name: value.name, - }; + return DeletePlayersByName.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -409,6 +389,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // @ts-ignore import { Baz as __Baz } from "./baz_type"; @@ -432,20 +414,20 @@ export namespace Foobar { export const Bar = { tag: "Bar" }; export const Har = (value: number): Foobar => ({ tag: "Har", value }); - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ - new SumTypeVariant("Baz", __Baz.getAlgebraicType()), + new SumTypeVariant("Baz", __Baz.getTypeScriptAlgebraicType()), new SumTypeVariant("Bar", AlgebraicType.createProductType([])), new SumTypeVariant("Har", AlgebraicType.createU32Type()), ]); } export function serialize(writer: BinaryWriter, value: Foobar): void { - Foobar.getAlgebraicType().serialize(writer, value); + Foobar.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Foobar { - return Foobar.getAlgebraicType().deserialize(reader); + return Foobar.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -493,6 +475,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { HasSpecialStuff } from "./has_special_stuff_type"; // @ts-ignore @@ -577,6 +561,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type HasSpecialStuff = { identity: Identity, @@ -591,7 +577,7 @@ export namespace HasSpecialStuff { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("identity", AlgebraicType.createIdentityType()), new ProductTypeElement("address", AlgebraicType.createAddressType()), @@ -599,19 +585,11 @@ export namespace HasSpecialStuff { } export function serialize(writer: BinaryWriter, value: HasSpecialStuff): void { - const converted = { - identity: value.identity, - address: value.address, - }; - HasSpecialStuff.getAlgebraicType().serialize(writer, converted); + HasSpecialStuff.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): HasSpecialStuff { - const value = HasSpecialStuff.getAlgebraicType().deserialize(reader); - return { - identity: value.identity, - address: value.address, - }; + return HasSpecialStuff.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -655,6 +633,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type IdentityConnected = {}; @@ -667,21 +647,17 @@ export namespace IdentityConnected { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ ]); } export function serialize(writer: BinaryWriter, value: IdentityConnected): void { - const converted = { - }; - IdentityConnected.getAlgebraicType().serialize(writer, converted); + IdentityConnected.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): IdentityConnected { - const value = IdentityConnected.getAlgebraicType().deserialize(reader); - return { - }; + return IdentityConnected.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -724,6 +700,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // Import and reexport all reducer arg types @@ -800,80 +778,80 @@ const REMOTE_MODULE = { tables: { has_special_stuff: { tableName: "has_special_stuff", - rowType: HasSpecialStuff.getAlgebraicType(), + rowType: HasSpecialStuff.getTypeScriptAlgebraicType(), }, pk_multi_identity: { tableName: "pk_multi_identity", - rowType: PkMultiIdentity.getAlgebraicType(), + rowType: PkMultiIdentity.getTypeScriptAlgebraicType(), primaryKey: "id", }, points: { tableName: "points", - rowType: Point.getAlgebraicType(), + rowType: Point.getTypeScriptAlgebraicType(), }, private: { tableName: "private", - rowType: Private.getAlgebraicType(), + rowType: Private.getTypeScriptAlgebraicType(), }, repeating_test_arg: { tableName: "repeating_test_arg", - rowType: RepeatingTestArg.getAlgebraicType(), + rowType: RepeatingTestArg.getTypeScriptAlgebraicType(), primaryKey: "scheduled_id", }, test_a: { tableName: "test_a", - rowType: TestA.getAlgebraicType(), + rowType: TestA.getTypeScriptAlgebraicType(), }, test_d: { tableName: "test_d", - rowType: TestD.getAlgebraicType(), + rowType: TestD.getTypeScriptAlgebraicType(), }, test_e: { tableName: "test_e", - rowType: TestE.getAlgebraicType(), + rowType: TestE.getTypeScriptAlgebraicType(), primaryKey: "id", }, test_f: { tableName: "test_f", - rowType: TestFoobar.getAlgebraicType(), + rowType: TestFoobar.getTypeScriptAlgebraicType(), }, }, reducers: { __identity_connected__: { reducerName: "__identity_connected__", - argsType: IdentityConnected.getAlgebraicType(), + argsType: IdentityConnected.getTypeScriptAlgebraicType(), }, __init__: { reducerName: "__init__", - argsType: Init.getAlgebraicType(), + argsType: Init.getTypeScriptAlgebraicType(), }, add_player: { reducerName: "add_player", - argsType: AddPlayer.getAlgebraicType(), + argsType: AddPlayer.getTypeScriptAlgebraicType(), }, add_private: { reducerName: "add_private", - argsType: AddPrivate.getAlgebraicType(), + argsType: AddPrivate.getTypeScriptAlgebraicType(), }, delete_player: { reducerName: "delete_player", - argsType: DeletePlayer.getAlgebraicType(), + argsType: DeletePlayer.getTypeScriptAlgebraicType(), }, delete_players_by_name: { reducerName: "delete_players_by_name", - argsType: DeletePlayersByName.getAlgebraicType(), + argsType: DeletePlayersByName.getTypeScriptAlgebraicType(), }, query_private: { reducerName: "query_private", - argsType: QueryPrivate.getAlgebraicType(), + argsType: QueryPrivate.getTypeScriptAlgebraicType(), }, repeating_test: { reducerName: "repeating_test", - argsType: RepeatingTest.getAlgebraicType(), + argsType: RepeatingTest.getTypeScriptAlgebraicType(), }, test: { reducerName: "test", - argsType: Test.getAlgebraicType(), + argsType: Test.getTypeScriptAlgebraicType(), }, }, // Constructors which are used by the DBConnectionImpl to @@ -935,7 +913,7 @@ export class RemoteReducers { addPlayer(name: string) { const __args = { name }; let __writer = new BinaryWriter(1024); - AddPlayer.getAlgebraicType().serialize(__writer, __args); + AddPlayer.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("add_player", __argsBuffer); } @@ -951,7 +929,7 @@ export class RemoteReducers { addPrivate(name: string) { const __args = { name }; let __writer = new BinaryWriter(1024); - AddPrivate.getAlgebraicType().serialize(__writer, __args); + AddPrivate.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("add_private", __argsBuffer); } @@ -967,7 +945,7 @@ export class RemoteReducers { deletePlayer(id: bigint) { const __args = { id }; let __writer = new BinaryWriter(1024); - DeletePlayer.getAlgebraicType().serialize(__writer, __args); + DeletePlayer.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("delete_player", __argsBuffer); } @@ -983,7 +961,7 @@ export class RemoteReducers { deletePlayersByName(name: string) { const __args = { name }; let __writer = new BinaryWriter(1024); - DeletePlayersByName.getAlgebraicType().serialize(__writer, __args); + DeletePlayersByName.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("delete_players_by_name", __argsBuffer); } @@ -1011,7 +989,7 @@ export class RemoteReducers { repeatingTest(arg: RepeatingTestArg) { const __args = { arg }; let __writer = new BinaryWriter(1024); - RepeatingTest.getAlgebraicType().serialize(__writer, __args); + RepeatingTest.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("repeating_test", __argsBuffer); } @@ -1027,7 +1005,7 @@ export class RemoteReducers { test(arg: TestA, arg2: TestB, arg3: NamespaceTestC, arg4: NamespaceTestF) { const __args = { arg, arg2, arg3, arg4 }; let __writer = new BinaryWriter(1024); - Test.getAlgebraicType().serialize(__writer, __args); + Test.getTypeScriptAlgebraicType().serialize(__writer, __args); let __argsBuffer = __writer.getBuffer(); this.connection.callReducer("test", __argsBuffer); } @@ -1045,49 +1023,40 @@ export class RemoteReducers { export class RemoteTables { constructor(private connection: DBConnectionImpl) {} - #hasSpecialStuff = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.has_special_stuff); get hasSpecialStuff(): HasSpecialStuffTableHandle { - return new HasSpecialStuffTableHandle(this.#hasSpecialStuff); + return new HasSpecialStuffTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.has_special_stuff)); } - #pkMultiIdentity = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.pk_multi_identity); get pkMultiIdentity(): PkMultiIdentityTableHandle { - return new PkMultiIdentityTableHandle(this.#pkMultiIdentity); + return new PkMultiIdentityTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.pk_multi_identity)); } - #points = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.points); get points(): PointsTableHandle { - return new PointsTableHandle(this.#points); + return new PointsTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.points)); } - #private = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.private); get private(): PrivateTableHandle { - return new PrivateTableHandle(this.#private); + return new PrivateTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.private)); } - #repeatingTestArg = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.repeating_test_arg); get repeatingTestArg(): RepeatingTestArgTableHandle { - return new RepeatingTestArgTableHandle(this.#repeatingTestArg); + return new RepeatingTestArgTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.repeating_test_arg)); } - #testA = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_a); get testA(): TestATableHandle { - return new TestATableHandle(this.#testA); + return new TestATableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_a)); } - #testD = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_d); get testD(): TestDTableHandle { - return new TestDTableHandle(this.#testD); + return new TestDTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_d)); } - #testE = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_e); get testE(): TestETableHandle { - return new TestETableHandle(this.#testE); + return new TestETableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_e)); } - #testF = this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_f); get testF(): TestFTableHandle { - return new TestFTableHandle(this.#testF); + return new TestFTableHandle(this.connection.clientCache.getOrCreateTable(REMOTE_MODULE.tables.test_f)); } } @@ -1136,6 +1105,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type Init = {}; @@ -1148,21 +1119,17 @@ export namespace Init { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ ]); } export function serialize(writer: BinaryWriter, value: Init): void { - const converted = { - }; - Init.getAlgebraicType().serialize(writer, converted); + Init.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Init { - const value = Init.getAlgebraicType().deserialize(reader); - return { - }; + return Init.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1205,6 +1172,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // A namespace for generated variants and helper functions. export namespace NamespaceTestC { @@ -1223,7 +1192,7 @@ export namespace NamespaceTestC { export const Foo = { tag: "Foo" }; export const Bar = { tag: "Bar" }; - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ new SumTypeVariant("Foo", AlgebraicType.createProductType([])), new SumTypeVariant("Bar", AlgebraicType.createProductType([])), @@ -1231,11 +1200,11 @@ export namespace NamespaceTestC { } export function serialize(writer: BinaryWriter, value: NamespaceTestC): void { - NamespaceTestC.getAlgebraicType().serialize(writer, value); + NamespaceTestC.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): NamespaceTestC { - return NamespaceTestC.getAlgebraicType().deserialize(reader); + return NamespaceTestC.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1283,6 +1252,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // A namespace for generated variants and helper functions. export namespace NamespaceTestF { @@ -1303,7 +1274,7 @@ export namespace NamespaceTestF { export const Bar = { tag: "Bar" }; export const Baz = (value: string): NamespaceTestF => ({ tag: "Baz", value }); - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ new SumTypeVariant("Foo", AlgebraicType.createProductType([])), new SumTypeVariant("Bar", AlgebraicType.createProductType([])), @@ -1312,11 +1283,11 @@ export namespace NamespaceTestF { } export function serialize(writer: BinaryWriter, value: NamespaceTestF): void { - NamespaceTestF.getAlgebraicType().serialize(writer, value); + NamespaceTestF.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): NamespaceTestF { - return NamespaceTestF.getAlgebraicType().deserialize(reader); + return NamespaceTestF.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1364,6 +1335,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { PkMultiIdentity } from "./pk_multi_identity_type"; // @ts-ignore @@ -1409,7 +1382,7 @@ export class PkMultiIdentityTableHandle { // if such a row is present in the client cache. find: (col_val: number): PkMultiIdentity | undefined => { for (let row of this.tableCache.iter()) { - if (row.id === col_val) { + if (deepEqual(row.id, col_val)) { return row; } } @@ -1431,7 +1404,7 @@ export class PkMultiIdentityTableHandle { // if such a row is present in the client cache. find: (col_val: number): PkMultiIdentity | undefined => { for (let row of this.tableCache.iter()) { - if (row.other === col_val) { + if (deepEqual(row.other, col_val)) { return row; } } @@ -1500,6 +1473,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type PkMultiIdentity = { id: number, @@ -1514,7 +1489,7 @@ export namespace PkMultiIdentity { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("id", AlgebraicType.createU32Type()), new ProductTypeElement("other", AlgebraicType.createU32Type()), @@ -1522,19 +1497,11 @@ export namespace PkMultiIdentity { } export function serialize(writer: BinaryWriter, value: PkMultiIdentity): void { - const converted = { - id: value.id, - other: value.other, - }; - PkMultiIdentity.getAlgebraicType().serialize(writer, converted); + PkMultiIdentity.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): PkMultiIdentity { - const value = PkMultiIdentity.getAlgebraicType().deserialize(reader); - return { - id: value.id, - other: value.other, - }; + return PkMultiIdentity.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1578,6 +1545,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type Point = { x: bigint, @@ -1592,7 +1561,7 @@ export namespace Point { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("x", AlgebraicType.createI64Type()), new ProductTypeElement("y", AlgebraicType.createI64Type()), @@ -1600,19 +1569,11 @@ export namespace Point { } export function serialize(writer: BinaryWriter, value: Point): void { - const converted = { - x: value.x, - y: value.y, - }; - Point.getAlgebraicType().serialize(writer, converted); + Point.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Point { - const value = Point.getAlgebraicType().deserialize(reader); - return { - x: value.x, - y: value.y, - }; + return Point.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1656,6 +1617,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { Point } from "./point_type"; // @ts-ignore @@ -1740,6 +1703,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { Private } from "./private_type"; // @ts-ignore @@ -1824,6 +1789,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type Private = { name: string, @@ -1837,24 +1804,18 @@ export namespace Private { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("name", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: Private): void { - const converted = { - name: value.name, - }; - Private.getAlgebraicType().serialize(writer, converted); + Private.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Private { - const value = Private.getAlgebraicType().deserialize(reader); - return { - name: value.name, - }; + return Private.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1898,6 +1859,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type QueryPrivate = {}; @@ -1910,21 +1873,17 @@ export namespace QueryPrivate { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ ]); } export function serialize(writer: BinaryWriter, value: QueryPrivate): void { - const converted = { - }; - QueryPrivate.getAlgebraicType().serialize(writer, converted); + QueryPrivate.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): QueryPrivate { - const value = QueryPrivate.getAlgebraicType().deserialize(reader); - return { - }; + return QueryPrivate.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -1967,6 +1926,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { RepeatingTestArg } from "./repeating_test_arg_type"; // @ts-ignore @@ -2012,7 +1973,7 @@ export class RepeatingTestArgTableHandle { // if such a row is present in the client cache. find: (col_val: bigint): RepeatingTestArg | undefined => { for (let row of this.tableCache.iter()) { - if (row.scheduled_id === col_val) { + if (deepEqual(row.scheduled_id, col_val)) { return row; } } @@ -2081,6 +2042,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type RepeatingTestArg = { prevTime: bigint, @@ -2096,30 +2059,20 @@ export namespace RepeatingTestArg { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ - new ProductTypeElement("prev_time", AlgebraicType.createU64Type()), - new ProductTypeElement("scheduled_id", AlgebraicType.createU64Type()), - new ProductTypeElement("scheduled_at", AlgebraicType.createScheduleAtType()), + new ProductTypeElement("prevTime", AlgebraicType.createU64Type()), + new ProductTypeElement("scheduledId", AlgebraicType.createU64Type()), + new ProductTypeElement("scheduledAt", AlgebraicType.createScheduleAtType()), ]); } export function serialize(writer: BinaryWriter, value: RepeatingTestArg): void { - const converted = { - prev_time: value.prevTime, - scheduled_id: value.scheduledId, - scheduled_at: value.scheduledAt, - }; - RepeatingTestArg.getAlgebraicType().serialize(writer, converted); + RepeatingTestArg.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): RepeatingTestArg { - const value = RepeatingTestArg.getAlgebraicType().deserialize(reader); - return { - prevTime: value.prev_time, - scheduledId: value.scheduled_id, - scheduledAt: value.scheduled_at, - }; + return RepeatingTestArg.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2163,6 +2116,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // @ts-ignore @@ -2180,24 +2135,18 @@ export namespace RepeatingTest { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ - new ProductTypeElement("arg", __RepeatingTestArg.getAlgebraicType()), + new ProductTypeElement("arg", __RepeatingTestArg.getTypeScriptAlgebraicType()), ]); } export function serialize(writer: BinaryWriter, value: RepeatingTest): void { - const converted = { - arg: value.arg, - }; - RepeatingTest.getAlgebraicType().serialize(writer, converted); + RepeatingTest.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): RepeatingTest { - const value = RepeatingTest.getAlgebraicType().deserialize(reader); - return { - arg: value.arg, - }; + return RepeatingTest.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2240,6 +2189,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { TestA } from "./test_a_type"; // @ts-ignore @@ -2324,6 +2275,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type TestA = { x: number, @@ -2339,7 +2292,7 @@ export namespace TestA { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("x", AlgebraicType.createU32Type()), new ProductTypeElement("y", AlgebraicType.createU32Type()), @@ -2348,21 +2301,11 @@ export namespace TestA { } export function serialize(writer: BinaryWriter, value: TestA): void { - const converted = { - x: value.x, - y: value.y, - z: value.z, - }; - TestA.getAlgebraicType().serialize(writer, converted); + TestA.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): TestA { - const value = TestA.getAlgebraicType().deserialize(reader); - return { - x: value.x, - y: value.y, - z: value.z, - }; + return TestA.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2406,6 +2349,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type TestB = { foo: string, @@ -2419,24 +2364,18 @@ export namespace TestB { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("foo", AlgebraicType.createStringType()), ]); } export function serialize(writer: BinaryWriter, value: TestB): void { - const converted = { - foo: value.foo, - }; - TestB.getAlgebraicType().serialize(writer, converted); + TestB.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): TestB { - const value = TestB.getAlgebraicType().deserialize(reader); - return { - foo: value.foo, - }; + return TestB.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2480,6 +2419,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { TestD } from "./test_d_type"; // @ts-ignore @@ -2567,6 +2508,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // @ts-ignore import { NamespaceTestC as __NamespaceTestC } from "./namespace_test_c_type"; @@ -2583,24 +2526,18 @@ export namespace TestD { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ - new ProductTypeElement("test_c", AlgebraicType.createOptionType(__NamespaceTestC.getAlgebraicType())), + new ProductTypeElement("testC", AlgebraicType.createOptionType(__NamespaceTestC.getTypeScriptAlgebraicType())), ]); } export function serialize(writer: BinaryWriter, value: TestD): void { - const converted = { - test_c: value.testC, - }; - TestD.getAlgebraicType().serialize(writer, converted); + TestD.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): TestD { - const value = TestD.getAlgebraicType().deserialize(reader); - return { - testC: value.test_c, - }; + return TestD.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2644,6 +2581,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { TestE } from "./test_e_type"; // @ts-ignore @@ -2689,7 +2628,7 @@ export class TestETableHandle { // if such a row is present in the client cache. find: (col_val: bigint): TestE | undefined => { for (let row of this.tableCache.iter()) { - if (row.id === col_val) { + if (deepEqual(row.id, col_val)) { return row; } } @@ -2758,6 +2697,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; export type TestE = { id: bigint, @@ -2772,7 +2713,7 @@ export namespace TestE { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ new ProductTypeElement("id", AlgebraicType.createU64Type()), new ProductTypeElement("name", AlgebraicType.createStringType()), @@ -2780,19 +2721,11 @@ export namespace TestE { } export function serialize(writer: BinaryWriter, value: TestE): void { - const converted = { - id: value.id, - name: value.name, - }; - TestE.getAlgebraicType().serialize(writer, converted); + TestE.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): TestE { - const value = TestE.getAlgebraicType().deserialize(reader); - return { - id: value.id, - name: value.name, - }; + return TestE.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -2836,6 +2769,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; import { TestFoobar } from "./test_foobar_type"; // @ts-ignore @@ -2923,6 +2858,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // @ts-ignore import { Foobar as __Foobar } from "./foobar_type"; @@ -2939,24 +2876,18 @@ export namespace TestFoobar { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ - new ProductTypeElement("field", __Foobar.getAlgebraicType()), + new ProductTypeElement("field", __Foobar.getTypeScriptAlgebraicType()), ]); } export function serialize(writer: BinaryWriter, value: TestFoobar): void { - const converted = { - field: value.field, - }; - TestFoobar.getAlgebraicType().serialize(writer, converted); + TestFoobar.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): TestFoobar { - const value = TestFoobar.getAlgebraicType().deserialize(reader); - return { - field: value.field, - }; + return TestFoobar.getTypeScriptAlgebraicType().deserialize(reader); } } @@ -3000,6 +2931,8 @@ import { SumTypeVariant, // @ts-ignore TableCache, + // @ts-ignore + deepEqual, } from "@clockworklabs/spacetimedb-sdk"; // @ts-ignore @@ -3026,33 +2959,21 @@ export namespace Test { * A function which returns this type represented as an AlgebraicType. * This function is derived from the AlgebraicType used to generate this type. */ - export function getAlgebraicType(): AlgebraicType { + export function getTypeScriptAlgebraicType(): AlgebraicType { return AlgebraicType.createProductType([ - new ProductTypeElement("arg", __TestA.getAlgebraicType()), - new ProductTypeElement("arg2", __TestB.getAlgebraicType()), - new ProductTypeElement("arg3", __NamespaceTestC.getAlgebraicType()), - new ProductTypeElement("arg4", __NamespaceTestF.getAlgebraicType()), + new ProductTypeElement("arg", __TestA.getTypeScriptAlgebraicType()), + new ProductTypeElement("arg2", __TestB.getTypeScriptAlgebraicType()), + new ProductTypeElement("arg3", __NamespaceTestC.getTypeScriptAlgebraicType()), + new ProductTypeElement("arg4", __NamespaceTestF.getTypeScriptAlgebraicType()), ]); } export function serialize(writer: BinaryWriter, value: Test): void { - const converted = { - arg: value.arg, - arg2: value.arg2, - arg3: value.arg3, - arg4: value.arg4, - }; - Test.getAlgebraicType().serialize(writer, converted); + Test.getTypeScriptAlgebraicType().serialize(writer, value); } export function deserialize(reader: BinaryReader): Test { - const value = Test.getAlgebraicType().deserialize(reader); - return { - arg: value.arg, - arg2: value.arg2, - arg3: value.arg3, - arg4: value.arg4, - }; + return Test.getTypeScriptAlgebraicType().deserialize(reader); } }