diff --git a/Cargo.lock b/Cargo.lock index dd4fc560b2e..ffb8a4c75ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,6 +444,14 @@ dependencies = [ "vsimd", ] +[[package]] +name = "basic-rs-template-module" +version = "0.1.0" +dependencies = [ + "log", + "spacetimedb 1.12.0", +] + [[package]] name = "benchmarks-module" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index d1b57371642..39803183e08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ members = [ "modules/keynote-benchmarks", "modules/perf-test", "modules/module-test", + "templates/basic-rs/spacetimedb", "templates/chat-console-rs/spacetimedb", "modules/sdk-test", "modules/sdk-test-connect-disconnect", diff --git a/crates/bindings-typescript/src/lib/autogen/function_visibility_type.ts b/crates/bindings-typescript/src/lib/autogen/function_visibility_type.ts new file mode 100644 index 00000000000..0b94830a87d --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/function_visibility_type.ts @@ -0,0 +1,19 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; + +// The tagged union or sum type for the algebraic type `FunctionVisibility`. +const FunctionVisibility = __t.enum('FunctionVisibility', { + Internal: __t.unit(), + ClientCallable: __t.unit(), +}); + +export default FunctionVisibility; diff --git a/crates/bindings-typescript/src/lib/autogen/raw_column_default_value_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_column_default_value_v_10_type.ts new file mode 100644 index 00000000000..5f37afa4604 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_column_default_value_v_10_type.ts @@ -0,0 +1,16 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; + +export default __t.object('RawColumnDefaultValueV10', { + colId: __t.u16(), + value: __t.byteArray(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_constraint_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_constraint_def_v_10_type.ts new file mode 100644 index 00000000000..76145329659 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_constraint_def_v_10_type.ts @@ -0,0 +1,19 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import RawConstraintDataV9 from './raw_constraint_data_v_9_type'; + +export default __t.object('RawConstraintDefV10', { + sourceName: __t.option(__t.string()), + get data() { + return RawConstraintDataV9; + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_index_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_index_def_v_10_type.ts new file mode 100644 index 00000000000..2a1913b7ae4 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_index_def_v_10_type.ts @@ -0,0 +1,20 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import RawIndexAlgorithm from './raw_index_algorithm_type'; + +export default __t.object('RawIndexDefV10', { + sourceName: __t.option(__t.string()), + accessorName: __t.option(__t.string()), + get algorithm() { + return RawIndexAlgorithm; + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_life_cycle_reducer_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_life_cycle_reducer_def_v_10_type.ts new file mode 100644 index 00000000000..7ccc26d79a3 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_life_cycle_reducer_def_v_10_type.ts @@ -0,0 +1,19 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import Lifecycle from './lifecycle_type'; + +export default __t.object('RawLifeCycleReducerDefV10', { + get lifecycleSpec() { + return Lifecycle; + }, + functionName: __t.string(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_module_def_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_module_def_type.ts index e0f91b646ff..40255921356 100644 --- a/crates/bindings-typescript/src/lib/autogen/raw_module_def_type.ts +++ b/crates/bindings-typescript/src/lib/autogen/raw_module_def_type.ts @@ -11,6 +11,7 @@ import { } from '../../lib/type_builders'; import RawModuleDefV8 from './raw_module_def_v_8_type'; import RawModuleDefV9 from './raw_module_def_v_9_type'; +import RawModuleDefV10 from './raw_module_def_v_10_type'; // The tagged union or sum type for the algebraic type `RawModuleDef`. const RawModuleDef = __t.enum('RawModuleDef', { @@ -20,6 +21,9 @@ const RawModuleDef = __t.enum('RawModuleDef', { get V9() { return RawModuleDefV9; }, + get V10() { + return RawModuleDefV10; + }, }); export default RawModuleDef; diff --git a/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_section_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_section_type.ts new file mode 100644 index 00000000000..dcf579b9fd6 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_section_type.ts @@ -0,0 +1,53 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import Typespace from './typespace_type'; +import RawRowLevelSecurityDefV9 from './raw_row_level_security_def_v_9_type'; +import RawTypeDefV10 from './raw_type_def_v_10_type'; +import RawTableDefV10 from './raw_table_def_v_10_type'; +import RawReducerDefV10 from './raw_reducer_def_v_10_type'; +import RawProcedureDefV10 from './raw_procedure_def_v_10_type'; +import RawViewDefV10 from './raw_view_def_v_10_type'; +import RawScheduleDefV10 from './raw_schedule_def_v_10_type'; +import RawLifeCycleReducerDefV10 from './raw_life_cycle_reducer_def_v_10_type'; + +// The tagged union or sum type for the algebraic type `RawModuleDefV10Section`. +const RawModuleDefV10Section = __t.enum('RawModuleDefV10Section', { + get Typespace() { + return Typespace; + }, + get Types() { + return __t.array(RawTypeDefV10); + }, + get Tables() { + return __t.array(RawTableDefV10); + }, + get Reducers() { + return __t.array(RawReducerDefV10); + }, + get Procedures() { + return __t.array(RawProcedureDefV10); + }, + get Views() { + return __t.array(RawViewDefV10); + }, + get Schedules() { + return __t.array(RawScheduleDefV10); + }, + get LifeCycleReducers() { + return __t.array(RawLifeCycleReducerDefV10); + }, + get RowLevelSecurity() { + return __t.array(RawRowLevelSecurityDefV9); + }, +}); + +export default RawModuleDefV10Section; diff --git a/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_type.ts new file mode 100644 index 00000000000..f12b1e66523 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_module_def_v_10_type.ts @@ -0,0 +1,18 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import RawModuleDefV10Section from './raw_module_def_v_10_section_type'; + +export default __t.object('RawModuleDefV10', { + get sections() { + return __t.array(RawModuleDefV10Section); + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_procedure_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_procedure_def_v_10_type.ts new file mode 100644 index 00000000000..1c2b312c126 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_procedure_def_v_10_type.ts @@ -0,0 +1,27 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import AlgebraicType from './algebraic_type_type'; +import ProductType from './product_type_type'; +import FunctionVisibility from './function_visibility_type'; + +export default __t.object('RawProcedureDefV10', { + sourceName: __t.string(), + get params() { + return ProductType; + }, + get returnType() { + return AlgebraicType; + }, + get visibility() { + return FunctionVisibility; + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_reducer_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_reducer_def_v_10_type.ts new file mode 100644 index 00000000000..2c40195ebb9 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_reducer_def_v_10_type.ts @@ -0,0 +1,30 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import AlgebraicType from './algebraic_type_type'; +import ProductType from './product_type_type'; +import FunctionVisibility from './function_visibility_type'; + +export default __t.object('RawReducerDefV10', { + sourceName: __t.string(), + get params() { + return ProductType; + }, + get visibility() { + return FunctionVisibility; + }, + get okReturnType() { + return AlgebraicType; + }, + get errReturnType() { + return AlgebraicType; + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_schedule_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_schedule_def_v_10_type.ts new file mode 100644 index 00000000000..7ad8b18bad1 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_schedule_def_v_10_type.ts @@ -0,0 +1,18 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; + +export default __t.object('RawScheduleDefV10', { + sourceName: __t.option(__t.string()), + tableName: __t.string(), + scheduleAtCol: __t.u16(), + functionName: __t.string(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_scoped_type_name_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_scoped_type_name_v_10_type.ts new file mode 100644 index 00000000000..91bf0da5915 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_scoped_type_name_v_10_type.ts @@ -0,0 +1,16 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; + +export default __t.object('RawScopedTypeNameV10', { + scope: __t.array(__t.string()), + sourceName: __t.string(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_sequence_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_sequence_def_v_10_type.ts new file mode 100644 index 00000000000..e5ebe17d853 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_sequence_def_v_10_type.ts @@ -0,0 +1,20 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; + +export default __t.object('RawSequenceDefV10', { + sourceName: __t.option(__t.string()), + column: __t.u16(), + start: __t.option(__t.i128()), + minValue: __t.option(__t.i128()), + maxValue: __t.option(__t.i128()), + increment: __t.i128(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_table_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_table_def_v_10_type.ts new file mode 100644 index 00000000000..47d112d4506 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_table_def_v_10_type.ts @@ -0,0 +1,41 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import TableType from './table_type_type'; +import TableAccess from './table_access_type'; +import RawIndexDefV10 from './raw_index_def_v_10_type'; +import RawConstraintDefV10 from './raw_constraint_def_v_10_type'; +import RawSequenceDefV10 from './raw_sequence_def_v_10_type'; +import RawColumnDefaultValueV10 from './raw_column_default_value_v_10_type'; + +export default __t.object('RawTableDefV10', { + sourceName: __t.string(), + productTypeRef: __t.u32(), + primaryKey: __t.array(__t.u16()), + get indexes() { + return __t.array(RawIndexDefV10); + }, + get constraints() { + return __t.array(RawConstraintDefV10); + }, + get sequences() { + return __t.array(RawSequenceDefV10); + }, + get tableType() { + return TableType; + }, + get tableAccess() { + return TableAccess; + }, + get defaultValues() { + return __t.array(RawColumnDefaultValueV10); + }, +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_type_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_type_def_v_10_type.ts new file mode 100644 index 00000000000..e3800eff3d2 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_type_def_v_10_type.ts @@ -0,0 +1,20 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import RawScopedTypeNameV10 from './raw_scoped_type_name_v_10_type'; + +export default __t.object('RawTypeDefV10', { + get sourceName() { + return RawScopedTypeNameV10; + }, + ty: __t.u32(), + customOrdering: __t.bool(), +}); diff --git a/crates/bindings-typescript/src/lib/autogen/raw_view_def_v_10_type.ts b/crates/bindings-typescript/src/lib/autogen/raw_view_def_v_10_type.ts new file mode 100644 index 00000000000..755076ed315 --- /dev/null +++ b/crates/bindings-typescript/src/lib/autogen/raw_view_def_v_10_type.ts @@ -0,0 +1,26 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +/* eslint-disable */ +/* tslint:disable */ +import { + TypeBuilder as __TypeBuilder, + t as __t, + type AlgebraicTypeType as __AlgebraicTypeType, + type Infer as __Infer, +} from '../../lib/type_builders'; +import AlgebraicType from './algebraic_type_type'; +import ProductType from './product_type_type'; + +export default __t.object('RawViewDefV10', { + sourceName: __t.string(), + index: __t.u32(), + isPublic: __t.bool(), + isAnonymous: __t.bool(), + get params() { + return ProductType; + }, + get returnType() { + return AlgebraicType; + }, +}); diff --git a/crates/bindings-typescript/src/sdk/client_api/index.ts b/crates/bindings-typescript/src/sdk/client_api/index.ts index 5b7fa1a1f21..8ffe5a062a1 100644 --- a/crates/bindings-typescript/src/sdk/client_api/index.ts +++ b/crates/bindings-typescript/src/sdk/client_api/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.3 (commit f9bca6a8df856d950360b40cbce744fcbffc9a63). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -121,7 +121,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.3' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, diff --git a/crates/bindings-typescript/test-app/src/module_bindings/index.ts b/crates/bindings-typescript/test-app/src/module_bindings/index.ts index 22483e31050..10c1dae7905 100644 --- a/crates/bindings-typescript/test-app/src/module_bindings/index.ts +++ b/crates/bindings-typescript/test-app/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.3 (commit f9bca6a8df856d950360b40cbce744fcbffc9a63). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -112,7 +112,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.3' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, diff --git a/sdks/csharp/tests~/SnapshotTests.cs b/sdks/csharp/tests~/SnapshotTests.cs index e5bbadfdc74..262ada709ad 100644 --- a/sdks/csharp/tests~/SnapshotTests.cs +++ b/sdks/csharp/tests~/SnapshotTests.cs @@ -231,9 +231,9 @@ private static byte[] Encode(in T value) where T : IStructuralReadWrite } private static readonly uint USER_TABLE_ID = 4097; - private static readonly string USER_TABLE_NAME = "user"; + private static readonly string USER_TABLE_NAME = "User"; private static readonly uint MESSAGE_TABLE_ID = 4098; - private static readonly string MESSAGE_TABLE_NAME = "message"; + private static readonly string MESSAGE_TABLE_NAME = "Message"; private static TableUpdate SampleUserInsert(string identity, string? name, bool online) => diff --git a/smoketests/tests/spacetimedb_init.py b/smoketests/tests/spacetimedb_init.py new file mode 100644 index 00000000000..aaf744040bd --- /dev/null +++ b/smoketests/tests/spacetimedb_init.py @@ -0,0 +1,285 @@ +import json +import os +import sys +import tempfile +import unittest +from pathlib import Path +import toml + +from .. import STDB_DIR, spacetime, pnpm, requires_dotnet, run_cmd + + +class TestSpacetimeInit(unittest.TestCase): + def get_templates(self): + templates_dir = STDB_DIR / "templates" + templates = [] + + for entry in templates_dir.iterdir(): + if not entry.is_dir(): + continue + + template_json = entry / ".template.json" + if not template_json.exists(): + continue + + with open(template_json) as f: + metadata = json.load(f) + + templates.append({ + "id": entry.name, + "server_lang": metadata["server_lang"], + "client_lang": metadata.get("client_lang"), + }) + + return templates + + def test_init_and_publish_all_templates(self): + templates = self.get_templates() + self.assertGreater(len(templates), 0, "No templates found") + + print(f"\nTesting {len(templates)} template(s)...") + print("="*60) + + results = {} + passed_count = 0 + failed_count = 0 + + for i, template in enumerate(templates, 1): + print(f"\n[{i}/{len(templates)}] Testing template: {template['id']}") + print("-" * 60) + with self.subTest(template=template["id"]): + try: + self._test_template(template) + results[template["id"]] = "[PASS]" + passed_count += 1 + print(f"[PASS] {template['id']}") + except Exception as e: + results[template["id"]] = f"[FAIL]: {str(e)}" + failed_count += 1 + print(f"[FAIL] {template['id']}: {str(e)}") + raise + + print("\n" + "="*60) + print("TEMPLATE TEST SUMMARY") + print("="*60) + for template_id, result in sorted(results.items()): + print(f"{template_id:30} {result}") + print("="*60) + + total = len(results) + print(f"TOTAL: {passed_count}/{total} passed\n") + + def _test_template(self, template): + with tempfile.TemporaryDirectory() as tmpdir: + project_name = f"test-{template['id']}" + project_path = Path(tmpdir) / project_name + + print(f" > Initializing project from template...") + spacetime( + "init", + "--template", template["id"], + "--project-path", str(project_path), + "--non-interactive", + project_name + ) + + self.assertTrue(project_path.exists(), f"Project directory not created for {template['id']}") + + if template.get("server_lang"): + server_path = project_path / "spacetimedb" + self.assertTrue(server_path.exists(), f"Server directory not found for {template['id']}") + + print(f" > Publishing server...") + self._publish_server(template, server_path) + + if template.get("client_lang"): + print(f" > Testing client...") + self._test_client(template, project_path) + + def _publish_server(self, template, server_path): + server_lang = template["server_lang"] + template_id = template["id"] + + if server_lang == "typescript": + self._setup_typescript_local_sdk(server_path) + pnpm("install", cwd=server_path) + + if server_lang == "rust": + self._setup_rust_local_sdk(server_path) + + if server_lang == "csharp": + self._setup_csharp_nuget(server_path) + + domain = f"test-{server_lang}-{os.urandom(8).hex()}" + print(f" > Building and publishing template '{template_id}' (language: {server_lang}) at {server_path}") + spacetime("publish", "-s", "local", "--yes", "--project-path", str(server_path), domain) + + spacetime("delete", "-s", "local", "--yes", domain) + + def _update_cargo_toml_dependency(self, cargo_toml_path, package_name, local_path): + """Replace crates.io dependency with local path dependency.""" + if not cargo_toml_path.exists(): + return + + cargo_data = toml.load(cargo_toml_path) + + if package_name in cargo_data.get("dependencies", {}): + cargo_data["dependencies"][package_name] = {"path": str(local_path)} + + with open(cargo_toml_path, 'w') as f: + toml.dump(cargo_data, f) + + def _setup_rust_local_sdk(self, server_path): + """Replace crates.io spacetimedb dependency with local path dependency.""" + print(f" > Setting up local Rust SDK...") + cargo_toml_path = server_path / "Cargo.toml" + rust_sdk_path = STDB_DIR / "crates/bindings" + self._update_cargo_toml_dependency(cargo_toml_path, "spacetimedb", rust_sdk_path) + + def _update_package_json_dependency(self, package_json_path, package_name, local_path): + """Replace npm package dependency with local path reference.""" + with open(package_json_path, 'r') as f: + package_data = json.load(f) + + # Always use absolute paths with forward slashes + # This works on both Windows and Unix, and handles different drives on Windows + abs_sdk_path = Path(local_path).absolute() + abs_path_str = str(abs_sdk_path).replace('\\', '/') + package_data["dependencies"][package_name] = abs_path_str + + with open(package_json_path, 'w') as f: + json.dump(package_data, f, indent=2) + + def _setup_typescript_local_sdk(self, server_path): + """Replace npm registry spacetimedb dependency with local SDK path reference.""" + print(f" > Setting up local TypeScript SDK...") + typescript_sdk_path = STDB_DIR / "crates/bindings-typescript" + + print(f" > DEBUG: TypeScript SDK path: {typescript_sdk_path}") + print(f" > DEBUG: TypeScript SDK absolute path: {typescript_sdk_path.absolute()}") + print(f" > DEBUG: Server path: {server_path}") + print(f" > DEBUG: Server path absolute: {server_path.absolute()}") + + print(f" > Building TypeScript SDK...") + pnpm("install", cwd=typescript_sdk_path) + pnpm("build", cwd=typescript_sdk_path) + + # Update package.json to use file: protocol + package_json_path = server_path / "package.json" + print(f" > DEBUG: package.json path: {package_json_path}") + + print(f" > DEBUG: Reading original package.json...") + with open(package_json_path, 'r') as f: + package_data = json.load(f) + print(f" > DEBUG: Original package.json dependencies: {json.dumps(package_data.get('dependencies', {}), indent=2)}") + + self._update_package_json_dependency(package_json_path, "spacetimedb", typescript_sdk_path) + + print(f" > DEBUG: Reading modified package.json...") + with open(package_json_path, 'r') as f: + package_data = json.load(f) + print(f" > DEBUG: Modified package.json dependencies: {json.dumps(package_data.get('dependencies', {}), indent=2)}") + print(f" > DEBUG: spacetimedb dependency value: {package_data.get('dependencies', {}).get('spacetimedb')}") + + # Remove lockfile since we changed the dependency + lockfile = server_path / "pnpm-lock.yaml" + if lockfile.exists(): + print(f" > DEBUG: Removing lockfile: {lockfile}") + lockfile.unlink() + else: + print(f" > DEBUG: No lockfile found at: {lockfile}") + + def _setup_csharp_nuget(self, server_path): + """Create a local nuget.config file to avoid polluting global NuGet sources""" + print(f" > Setting up C# NuGet sources...") + nuget_config = server_path / "nuget.config" + if not nuget_config.exists(): + nuget_config.write_text(""" + + + + + + +""") + + bindings = STDB_DIR / "crates/bindings-csharp" + packed_projects = ["BSATN.Runtime", "Runtime", "BSATN.Codegen", "Codegen"] + + for project in packed_projects: + run_cmd("dotnet", "pack", "-c", "Release", cwd=bindings / project) + path = bindings / project / "bin" / "Release" + project_name = f"SpacetimeDB.{project}" + run_cmd("dotnet", "nuget", "add", "source", str(path), "-n", project_name, "--configfile", str(nuget_config), cwd=server_path) + + # Pack ClientSDK for client projects + client_sdk = STDB_DIR / "sdks/csharp" + client_sdk_proj = client_sdk / "SpacetimeDB.ClientSDK.csproj" + run_cmd("dotnet", "pack", str(client_sdk_proj), "-c", "Release", "--configfile", str(nuget_config), cwd=server_path) + client_sdk_path = client_sdk / "bin~" / "Release" + run_cmd("dotnet", "nuget", "add", "source", str(client_sdk_path), "-n", "SpacetimeDB.ClientSDK", "--configfile", str(nuget_config), cwd=server_path) + + def _test_client(self, template, project_path): + """Test the client code based on the client language.""" + client_lang = template.get("client_lang") + + if client_lang == "rust": + print(f" - Building Rust client...") + # Setup local SDK for client + client_cargo_toml = project_path / "Cargo.toml" + rust_sdk_path = STDB_DIR / "sdks/rust" + self._update_cargo_toml_dependency(client_cargo_toml, "spacetimedb-sdk", rust_sdk_path) + run_cmd("cargo", "build", cwd=project_path) + + elif client_lang == "typescript": + print(f" - Type-checking TypeScript client...") + + # Update package.json to use file: protocol + package_json_path = project_path / "package.json" + typescript_sdk_path = STDB_DIR / "crates/bindings-typescript" + + print(f" - DEBUG: Client project path: {project_path}") + print(f" - DEBUG: Client package.json path: {package_json_path}") + print(f" - DEBUG: TypeScript SDK path: {typescript_sdk_path}") + + print(f" - DEBUG: Reading original client package.json...") + with open(package_json_path, 'r') as f: + package_data = json.load(f) + print(f" - DEBUG: Original client dependencies: {json.dumps(package_data.get('dependencies', {}), indent=2)}") + + self._update_package_json_dependency(package_json_path, "spacetimedb", typescript_sdk_path) + + print(f" - DEBUG: Reading modified client package.json...") + with open(package_json_path, 'r') as f: + package_data = json.load(f) + print(f" - DEBUG: Modified client dependencies: {json.dumps(package_data.get('dependencies', {}), indent=2)}") + + # Remove lockfile since we changed the dependency + lockfile = project_path / "pnpm-lock.yaml" + if lockfile.exists(): + print(f" - DEBUG: Removing client lockfile: {lockfile}") + lockfile.unlink() + + # Install other dependencies + pnpm("install", cwd=project_path) + + # Use vue-tsc if vue is a dependency, otherwise use tsc + with open(package_json_path, 'r') as f: + package_data = json.load(f) + has_vue = 'vue' in package_data.get('dependencies', {}) or 'vue' in package_data.get('devDependencies', {}) + + # Run TypeScript compiler in check mode + if has_vue: + print(f" - DEBUG: Using vue-tsc for Vue project") + # Skip Vue template type checking for now - vue-tsc has issues with ref unwrapping in templates + # TODO: Re-enable once vue-tsc properly handles DeepReadonly> unwrapping + print(f" - DEBUG: Skipping vue-tsc type checking (known template type issues)") + else: + print(f" - DEBUG: Using tsc for non-Vue project") + pnpm("exec", "tsc", "--noEmit", cwd=project_path) + + elif client_lang == "csharp": + print(f" - Building C# client...") + # Setup nuget for client if needed + self._setup_csharp_nuget(project_path) + run_cmd("dotnet", "build", cwd=project_path) diff --git a/templates/basic-cs/module_bindings/Reducers/Add.g.cs b/templates/basic-cs/module_bindings/Reducers/Add.g.cs new file mode 100644 index 00000000000..ece22145e9e --- /dev/null +++ b/templates/basic-cs/module_bindings/Reducers/Add.g.cs @@ -0,0 +1,73 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#nullable enable + +using System; +using SpacetimeDB.ClientApi; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SpacetimeDB.Types +{ + public sealed partial class RemoteReducers : RemoteBase + { + public delegate void AddHandler(ReducerEventContext ctx, string name); + public event AddHandler? OnAdd; + + public void Add(string name) + { + conn.InternalCallReducer(new Reducer.Add(name), this.SetCallReducerFlags.AddFlags); + } + + public bool InvokeAdd(ReducerEventContext ctx, Reducer.Add args) + { + if (OnAdd == null) + { + if (InternalOnUnhandledReducerError != null) + { + switch (ctx.Event.Status) + { + case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break; + case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break; + } + } + return false; + } + OnAdd( + ctx, + args.Name + ); + return true; + } + } + + public abstract partial class Reducer + { + [SpacetimeDB.Type] + [DataContract] + public sealed partial class Add : Reducer, IReducerArgs + { + [DataMember(Name = "name")] + public string Name; + + public Add(string Name) + { + this.Name = Name; + } + + public Add() + { + this.Name = ""; + } + + string IReducerArgs.ReducerName => "Add"; + } + } + + public sealed partial class SetReducerFlags + { + internal CallReducerFlags AddFlags; + public void Add(CallReducerFlags flags) => AddFlags = flags; + } +} diff --git a/templates/basic-cs/module_bindings/Reducers/SayHello.g.cs b/templates/basic-cs/module_bindings/Reducers/SayHello.g.cs new file mode 100644 index 00000000000..90af68404f9 --- /dev/null +++ b/templates/basic-cs/module_bindings/Reducers/SayHello.g.cs @@ -0,0 +1,59 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#nullable enable + +using System; +using SpacetimeDB.ClientApi; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SpacetimeDB.Types +{ + public sealed partial class RemoteReducers : RemoteBase + { + public delegate void SayHelloHandler(ReducerEventContext ctx); + public event SayHelloHandler? OnSayHello; + + public void SayHello() + { + conn.InternalCallReducer(new Reducer.SayHello(), this.SetCallReducerFlags.SayHelloFlags); + } + + public bool InvokeSayHello(ReducerEventContext ctx, Reducer.SayHello args) + { + if (OnSayHello == null) + { + if (InternalOnUnhandledReducerError != null) + { + switch (ctx.Event.Status) + { + case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break; + case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break; + } + } + return false; + } + OnSayHello( + ctx + ); + return true; + } + } + + public abstract partial class Reducer + { + [SpacetimeDB.Type] + [DataContract] + public sealed partial class SayHello : Reducer, IReducerArgs + { + string IReducerArgs.ReducerName => "SayHello"; + } + } + + public sealed partial class SetReducerFlags + { + internal CallReducerFlags SayHelloFlags; + public void SayHello(CallReducerFlags flags) => SayHelloFlags = flags; + } +} diff --git a/templates/basic-cs/module_bindings/SpacetimeDBClient.g.cs b/templates/basic-cs/module_bindings/SpacetimeDBClient.g.cs new file mode 100644 index 00000000000..e655f85ca26 --- /dev/null +++ b/templates/basic-cs/module_bindings/SpacetimeDBClient.g.cs @@ -0,0 +1,692 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +// This was generated using spacetimedb cli version 1.11.3 (commit ac10fc10f73238f4f2e937cc30aba3539bf2e4be). + +#nullable enable + +using System; +using SpacetimeDB.ClientApi; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SpacetimeDB.Types +{ + public sealed partial class RemoteReducers : RemoteBase + { + internal RemoteReducers(DbConnection conn, SetReducerFlags flags) : base(conn) => SetCallReducerFlags = flags; + internal readonly SetReducerFlags SetCallReducerFlags; + internal event Action? InternalOnUnhandledReducerError; + } + + public sealed partial class RemoteProcedures : RemoteBase + { + internal RemoteProcedures(DbConnection conn) : base(conn) { } + } + + public sealed partial class RemoteTables : RemoteTablesBase + { + public RemoteTables(DbConnection conn) + { + AddTable(Person = new(conn)); + } + } + + public sealed partial class SetReducerFlags { } + + public interface IRemoteDbContext : IDbContext + { + public event Action? OnUnhandledReducerError; + } + + public sealed class EventContext : IEventContext, IRemoteDbContext + { + private readonly DbConnection conn; + + /// + /// The event that caused this callback to run. + /// + public readonly Event Event; + + /// + /// Access to tables in the client cache, which stores a read-only replica of the remote database state. + /// + /// The returned DbView will have a method to access each table defined by the module. + /// + public RemoteTables Db => conn.Db; + /// + /// Access to reducers defined by the module. + /// + /// The returned RemoteReducers will have a method to invoke each reducer defined by the module, + /// plus methods for adding and removing callbacks on each of those reducers. + /// + public RemoteReducers Reducers => conn.Reducers; + /// + /// Access to setters for per-reducer flags. + /// + /// The returned SetReducerFlags will have a method to invoke, + /// for each reducer defined by the module, + /// which call-flags for the reducer can be set. + /// + public SetReducerFlags SetReducerFlags => conn.SetReducerFlags; + /// + /// Access to procedures defined by the module. + /// + /// The returned RemoteProcedures will have a method to invoke each procedure defined by the module, + /// with a callback for when the procedure completes and returns a value. + /// + public RemoteProcedures Procedures => conn.Procedures; + /// + /// Returns true if the connection is active, i.e. has not yet disconnected. + /// + public bool IsActive => conn.IsActive; + /// + /// Close the connection. + /// + /// Throws an error if the connection is already closed. + /// + public void Disconnect() + { + conn.Disconnect(); + } + /// + /// Start building a subscription. + /// + /// A builder-pattern constructor for subscribing to queries, + /// causing matching rows to be replicated into the client cache. + public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder(); + /// + /// Get the Identity of this connection. + /// + /// This method returns null if the connection was constructed anonymously + /// and we have not yet received our newly-generated Identity from the host. + /// + public Identity? Identity => conn.Identity; + /// + /// Get this connection's ConnectionId. + /// + public ConnectionId ConnectionId => conn.ConnectionId; + /// + /// Register a callback to be called when a reducer with no handler returns an error. + /// + public event Action? OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + + internal EventContext(DbConnection conn, Event Event) + { + this.conn = conn; + this.Event = Event; + } + } + + public sealed class ReducerEventContext : IReducerEventContext, IRemoteDbContext + { + private readonly DbConnection conn; + /// + /// The reducer event that caused this callback to run. + /// + public readonly ReducerEvent Event; + + /// + /// Access to tables in the client cache, which stores a read-only replica of the remote database state. + /// + /// The returned DbView will have a method to access each table defined by the module. + /// + public RemoteTables Db => conn.Db; + /// + /// Access to reducers defined by the module. + /// + /// The returned RemoteReducers will have a method to invoke each reducer defined by the module, + /// plus methods for adding and removing callbacks on each of those reducers. + /// + public RemoteReducers Reducers => conn.Reducers; + /// + /// Access to setters for per-reducer flags. + /// + /// The returned SetReducerFlags will have a method to invoke, + /// for each reducer defined by the module, + /// which call-flags for the reducer can be set. + /// + public SetReducerFlags SetReducerFlags => conn.SetReducerFlags; + /// + /// Access to procedures defined by the module. + /// + /// The returned RemoteProcedures will have a method to invoke each procedure defined by the module, + /// with a callback for when the procedure completes and returns a value. + /// + public RemoteProcedures Procedures => conn.Procedures; + /// + /// Returns true if the connection is active, i.e. has not yet disconnected. + /// + public bool IsActive => conn.IsActive; + /// + /// Close the connection. + /// + /// Throws an error if the connection is already closed. + /// + public void Disconnect() + { + conn.Disconnect(); + } + /// + /// Start building a subscription. + /// + /// A builder-pattern constructor for subscribing to queries, + /// causing matching rows to be replicated into the client cache. + public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder(); + /// + /// Get the Identity of this connection. + /// + /// This method returns null if the connection was constructed anonymously + /// and we have not yet received our newly-generated Identity from the host. + /// + public Identity? Identity => conn.Identity; + /// + /// Get this connection's ConnectionId. + /// + public ConnectionId ConnectionId => conn.ConnectionId; + /// + /// Register a callback to be called when a reducer with no handler returns an error. + /// + public event Action? OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + + internal ReducerEventContext(DbConnection conn, ReducerEvent reducerEvent) + { + this.conn = conn; + Event = reducerEvent; + } + } + + public sealed class ErrorContext : IErrorContext, IRemoteDbContext + { + private readonly DbConnection conn; + /// + /// The Exception that caused this error callback to be run. + /// + public readonly Exception Event; + Exception IErrorContext.Event + { + get + { + return Event; + } + } + + /// + /// Access to tables in the client cache, which stores a read-only replica of the remote database state. + /// + /// The returned DbView will have a method to access each table defined by the module. + /// + public RemoteTables Db => conn.Db; + /// + /// Access to reducers defined by the module. + /// + /// The returned RemoteReducers will have a method to invoke each reducer defined by the module, + /// plus methods for adding and removing callbacks on each of those reducers. + /// + public RemoteReducers Reducers => conn.Reducers; + /// + /// Access to setters for per-reducer flags. + /// + /// The returned SetReducerFlags will have a method to invoke, + /// for each reducer defined by the module, + /// which call-flags for the reducer can be set. + /// + public SetReducerFlags SetReducerFlags => conn.SetReducerFlags; + /// + /// Access to procedures defined by the module. + /// + /// The returned RemoteProcedures will have a method to invoke each procedure defined by the module, + /// with a callback for when the procedure completes and returns a value. + /// + public RemoteProcedures Procedures => conn.Procedures; + /// + /// Returns true if the connection is active, i.e. has not yet disconnected. + /// + public bool IsActive => conn.IsActive; + /// + /// Close the connection. + /// + /// Throws an error if the connection is already closed. + /// + public void Disconnect() + { + conn.Disconnect(); + } + /// + /// Start building a subscription. + /// + /// A builder-pattern constructor for subscribing to queries, + /// causing matching rows to be replicated into the client cache. + public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder(); + /// + /// Get the Identity of this connection. + /// + /// This method returns null if the connection was constructed anonymously + /// and we have not yet received our newly-generated Identity from the host. + /// + public Identity? Identity => conn.Identity; + /// + /// Get this connection's ConnectionId. + /// + public ConnectionId ConnectionId => conn.ConnectionId; + /// + /// Register a callback to be called when a reducer with no handler returns an error. + /// + public event Action? OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + + internal ErrorContext(DbConnection conn, Exception error) + { + this.conn = conn; + Event = error; + } + } + + public sealed class SubscriptionEventContext : ISubscriptionEventContext, IRemoteDbContext + { + private readonly DbConnection conn; + + /// + /// Access to tables in the client cache, which stores a read-only replica of the remote database state. + /// + /// The returned DbView will have a method to access each table defined by the module. + /// + public RemoteTables Db => conn.Db; + /// + /// Access to reducers defined by the module. + /// + /// The returned RemoteReducers will have a method to invoke each reducer defined by the module, + /// plus methods for adding and removing callbacks on each of those reducers. + /// + public RemoteReducers Reducers => conn.Reducers; + /// + /// Access to setters for per-reducer flags. + /// + /// The returned SetReducerFlags will have a method to invoke, + /// for each reducer defined by the module, + /// which call-flags for the reducer can be set. + /// + public SetReducerFlags SetReducerFlags => conn.SetReducerFlags; + /// + /// Access to procedures defined by the module. + /// + /// The returned RemoteProcedures will have a method to invoke each procedure defined by the module, + /// with a callback for when the procedure completes and returns a value. + /// + public RemoteProcedures Procedures => conn.Procedures; + /// + /// Returns true if the connection is active, i.e. has not yet disconnected. + /// + public bool IsActive => conn.IsActive; + /// + /// Close the connection. + /// + /// Throws an error if the connection is already closed. + /// + public void Disconnect() + { + conn.Disconnect(); + } + /// + /// Start building a subscription. + /// + /// A builder-pattern constructor for subscribing to queries, + /// causing matching rows to be replicated into the client cache. + public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder(); + /// + /// Get the Identity of this connection. + /// + /// This method returns null if the connection was constructed anonymously + /// and we have not yet received our newly-generated Identity from the host. + /// + public Identity? Identity => conn.Identity; + /// + /// Get this connection's ConnectionId. + /// + public ConnectionId ConnectionId => conn.ConnectionId; + /// + /// Register a callback to be called when a reducer with no handler returns an error. + /// + public event Action? OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + + internal SubscriptionEventContext(DbConnection conn) + { + this.conn = conn; + } + } + + public sealed class ProcedureEventContext : IProcedureEventContext, IRemoteDbContext + { + private readonly DbConnection conn; + /// + /// The procedure event that caused this callback to run. + /// + public readonly ProcedureEvent Event; + + /// + /// Access to tables in the client cache, which stores a read-only replica of the remote database state. + /// + /// The returned DbView will have a method to access each table defined by the module. + /// + public RemoteTables Db => conn.Db; + /// + /// Access to reducers defined by the module. + /// + /// The returned RemoteReducers will have a method to invoke each reducer defined by the module, + /// plus methods for adding and removing callbacks on each of those reducers. + /// + public RemoteReducers Reducers => conn.Reducers; + /// + /// Access to setters for per-reducer flags. + /// + /// The returned SetReducerFlags will have a method to invoke, + /// for each reducer defined by the module, + /// which call-flags for the reducer can be set. + /// + public SetReducerFlags SetReducerFlags => conn.SetReducerFlags; + /// + /// Access to procedures defined by the module. + /// + /// The returned RemoteProcedures will have a method to invoke each procedure defined by the module, + /// with a callback for when the procedure completes and returns a value. + /// + public RemoteProcedures Procedures => conn.Procedures; + /// + /// Returns true if the connection is active, i.e. has not yet disconnected. + /// + public bool IsActive => conn.IsActive; + /// + /// Close the connection. + /// + /// Throws an error if the connection is already closed. + /// + public void Disconnect() + { + conn.Disconnect(); + } + /// + /// Start building a subscription. + /// + /// A builder-pattern constructor for subscribing to queries, + /// causing matching rows to be replicated into the client cache. + public SubscriptionBuilder SubscriptionBuilder() => conn.SubscriptionBuilder(); + /// + /// Get the Identity of this connection. + /// + /// This method returns null if the connection was constructed anonymously + /// and we have not yet received our newly-generated Identity from the host. + /// + public Identity? Identity => conn.Identity; + /// + /// Get this connection's ConnectionId. + /// + public ConnectionId ConnectionId => conn.ConnectionId; + /// + /// Register a callback to be called when a reducer with no handler returns an error. + /// + public event Action? OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + + internal ProcedureEventContext(DbConnection conn, ProcedureEvent Event) + { + this.conn = conn; + this.Event = Event; + } + } + + /// + /// Builder-pattern constructor for subscription queries. + /// + public sealed class SubscriptionBuilder + { + private readonly IDbConnection conn; + + private event Action? Applied; + private event Action? Error; + + /// + /// Private API, use conn.SubscriptionBuilder() instead. + /// + public SubscriptionBuilder(IDbConnection conn) + { + this.conn = conn; + } + + /// + /// Register a callback to run when the subscription is applied. + /// + public SubscriptionBuilder OnApplied( + Action callback + ) + { + Applied += callback; + return this; + } + + /// + /// Register a callback to run when the subscription fails. + /// + /// Note that this callback may run either when attempting to apply the subscription, + /// in which case Self::on_applied will never run, + /// or later during the subscription's lifetime if the module's interface changes, + /// in which case Self::on_applied may have already run. + /// + public SubscriptionBuilder OnError( + Action callback + ) + { + Error += callback; + return this; + } + + /// + /// Add a typed query to this subscription. + /// + /// This is the entry point for building subscriptions without writing SQL by hand. + /// Once a typed query is added, only typed queries may follow (SQL and typed queries cannot be mixed). + /// + public TypedSubscriptionBuilder AddQuery( + Func> build + ) + { + var typed = new TypedSubscriptionBuilder(conn, Applied, Error); + return typed.AddQuery(build); + } + + /// + /// Subscribe to the following SQL queries. + /// + /// This method returns immediately, with the data not yet added to the DbConnection. + /// The provided callbacks will be invoked once the data is returned from the remote server. + /// Data from all the provided queries will be returned at the same time. + /// + /// See the SpacetimeDB SQL docs for more information on SQL syntax: + /// https://spacetimedb.com/docs/sql + /// + public SubscriptionHandle Subscribe( + string[] querySqls + ) => new(conn, Applied, Error, querySqls); + + /// + /// Subscribe to all rows from all tables. + /// + /// This method is intended as a convenience + /// for applications where client-side memory use and network bandwidth are not concerns. + /// Applications where these resources are a constraint + /// should register more precise queries via Self.Subscribe + /// in order to replicate only the subset of data which the client needs to function. + /// + /// This method should not be combined with Self.Subscribe on the same DbConnection. + /// A connection may either Self.Subscribe to particular queries, + /// or Self.SubscribeToAllTables, but not both. + /// Attempting to call Self.Subscribe + /// on a DbConnection that has previously used Self.SubscribeToAllTables, + /// or vice versa, may misbehave in any number of ways, + /// including dropping subscriptions, corrupting the client cache, or panicking. + /// + public void SubscribeToAllTables() + { + // Make sure we use the legacy handle constructor here, even though there's only 1 query. + // We drop the error handler, since it can't be called for legacy subscriptions. + new SubscriptionHandle( + conn, + Applied, + new string[] { "SELECT * FROM *" } + ); + } + } + + public sealed class SubscriptionHandle : SubscriptionHandleBase + { + /// + /// Internal API. Construct SubscriptionHandles using conn.SubscriptionBuilder. + /// + public SubscriptionHandle(IDbConnection conn, Action? onApplied, string[] querySqls) : base(conn, onApplied, querySqls) + { } + + /// + /// Internal API. Construct SubscriptionHandles using conn.SubscriptionBuilder. + /// + public SubscriptionHandle( + IDbConnection conn, + Action? onApplied, + Action? onError, + string[] querySqls + ) : base(conn, onApplied, onError, querySqls) + { } + } + + public sealed class QueryBuilder + { + public From From { get; } = new(); + } + + public sealed class From + { + public global::SpacetimeDB.Table Person() => new("Person", new PersonCols("Person"), new PersonIxCols("Person")); + } + + public sealed class TypedSubscriptionBuilder + { + private readonly IDbConnection conn; + private Action? Applied; + private Action? Error; + private readonly List querySqls = new(); + + internal TypedSubscriptionBuilder(IDbConnection conn, Action? applied, Action? error) + { + this.conn = conn; + Applied = applied; + Error = error; + } + + public TypedSubscriptionBuilder OnApplied(Action callback) + { + Applied += callback; + return this; + } + + public TypedSubscriptionBuilder OnError(Action callback) + { + Error += callback; + return this; + } + + public TypedSubscriptionBuilder AddQuery(Func> build) + { + var qb = new QueryBuilder(); + querySqls.Add(build(qb).ToSql()); + return this; + } + + public SubscriptionHandle Subscribe() => new(conn, Applied, Error, querySqls.ToArray()); + } + + public abstract partial class Reducer + { + private Reducer() { } + } + + public abstract partial class Procedure + { + private Procedure() { } + } + + public sealed class DbConnection : DbConnectionBase + { + public override RemoteTables Db { get; } + public readonly RemoteReducers Reducers; + public readonly SetReducerFlags SetReducerFlags = new(); + public readonly RemoteProcedures Procedures; + + public DbConnection() + { + Db = new(this); + Reducers = new(this, SetReducerFlags); + Procedures = new(this); + } + + protected override Reducer ToReducer(TransactionUpdate update) + { + var encodedArgs = update.ReducerCall.Args; + return update.ReducerCall.ReducerName switch + { + "Add" => BSATNHelpers.Decode(encodedArgs), + "SayHello" => BSATNHelpers.Decode(encodedArgs), + "" => throw new SpacetimeDBEmptyReducerNameException("Reducer name is empty"), + var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}") + }; + } + + protected override IEventContext ToEventContext(Event Event) => + new EventContext(this, Event); + + protected override IReducerEventContext ToReducerEventContext(ReducerEvent reducerEvent) => + new ReducerEventContext(this, reducerEvent); + + protected override ISubscriptionEventContext MakeSubscriptionEventContext() => + new SubscriptionEventContext(this); + + protected override IErrorContext ToErrorContext(Exception exception) => + new ErrorContext(this, exception); + + protected override IProcedureEventContext ToProcedureEventContext(ProcedureEvent procedureEvent) => + new ProcedureEventContext(this, procedureEvent); + + protected override bool Dispatch(IReducerEventContext context, Reducer reducer) + { + var eventContext = (ReducerEventContext)context; + return reducer switch + { + Reducer.Add args => Reducers.InvokeAdd(eventContext, args), + Reducer.SayHello args => Reducers.InvokeSayHello(eventContext, args), + _ => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}") + }; + } + + public SubscriptionBuilder SubscriptionBuilder() => new(this); + public event Action OnUnhandledReducerError + { + add => Reducers.InternalOnUnhandledReducerError += value; + remove => Reducers.InternalOnUnhandledReducerError -= value; + } + } +} diff --git a/templates/basic-cs/module_bindings/Tables/Person.g.cs b/templates/basic-cs/module_bindings/Tables/Person.g.cs new file mode 100644 index 00000000000..07943203a85 --- /dev/null +++ b/templates/basic-cs/module_bindings/Tables/Person.g.cs @@ -0,0 +1,45 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#nullable enable + +using System; +using SpacetimeDB.BSATN; +using SpacetimeDB.ClientApi; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SpacetimeDB.Types +{ + public sealed partial class RemoteTables + { + public sealed class PersonHandle : RemoteTableHandle + { + protected override string RemoteTableName => "Person"; + + internal PersonHandle(DbConnection conn) : base(conn) + { + } + } + + public readonly PersonHandle Person; + } + + public sealed class PersonCols + { + public global::SpacetimeDB.Col Name { get; } + + public PersonCols(string tableName) + { + Name = new global::SpacetimeDB.Col(tableName, "Name"); + } + } + + public sealed class PersonIxCols + { + + public PersonIxCols(string tableName) + { + } + } +} diff --git a/templates/basic-cs/module_bindings/Types/Person.g.cs b/templates/basic-cs/module_bindings/Types/Person.g.cs new file mode 100644 index 00000000000..4746594c57b --- /dev/null +++ b/templates/basic-cs/module_bindings/Types/Person.g.cs @@ -0,0 +1,29 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#nullable enable + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SpacetimeDB.Types +{ + [SpacetimeDB.Type] + [DataContract] + public sealed partial class Person + { + [DataMember(Name = "Name")] + public string Name; + + public Person(string Name) + { + this.Name = Name; + } + + public Person() + { + this.Name = ""; + } + } +} diff --git a/templates/basic-rs/Cargo.toml b/templates/basic-rs/Cargo.toml index 6704d940f83..a2c7ae27faa 100644 --- a/templates/basic-rs/Cargo.toml +++ b/templates/basic-rs/Cargo.toml @@ -3,5 +3,8 @@ name = "spacetimedb-client" version = "0.1.0" edition = "2021" +[workspace] +exclude = ["spacetimedb"] + [dependencies] spacetimedb-sdk = { path = "../../sdks/rust" } diff --git a/templates/basic-rs/src/module_bindings/add_reducer.rs b/templates/basic-rs/src/module_bindings/add_reducer.rs new file mode 100644 index 00000000000..5dcce528d76 --- /dev/null +++ b/templates/basic-rs/src/module_bindings/add_reducer.rs @@ -0,0 +1,96 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct AddArgs { + pub name: String, +} + +impl From for super::Reducer { + fn from(args: AddArgs) -> Self { + Self::Add { name: args.name } + } +} + +impl __sdk::InModule for AddArgs { + type Module = super::RemoteModule; +} + +pub struct AddCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `add`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait add { + /// Request that the remote module invoke the reducer `add` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_add`] callbacks. + fn add(&self, name: String) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `add`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`AddCallbackId`] can be passed to [`Self::remove_on_add`] + /// to cancel the callback. + fn on_add(&self, callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static) -> AddCallbackId; + /// Cancel a callback previously registered by [`Self::on_add`], + /// causing it not to run in the future. + fn remove_on_add(&self, callback: AddCallbackId); +} + +impl add for super::RemoteReducers { + fn add(&self, name: String) -> __sdk::Result<()> { + self.imp.call_reducer("add", AddArgs { name }) + } + fn on_add(&self, mut callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static) -> AddCallbackId { + AddCallbackId(self.imp.on_reducer( + "add", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::Add { name }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, name) + }), + )) + } + fn remove_on_add(&self, callback: AddCallbackId) { + self.imp.remove_on_reducer("add", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `add`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_add { + /// Set the call-reducer flags for the reducer `add` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn add(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_add for super::SetReducerFlags { + fn add(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("add", flags); + } +} diff --git a/templates/basic-rs/src/module_bindings/identity_connected_reducer.rs b/templates/basic-rs/src/module_bindings/identity_connected_reducer.rs new file mode 100644 index 00000000000..5c2d5e0df4e --- /dev/null +++ b/templates/basic-rs/src/module_bindings/identity_connected_reducer.rs @@ -0,0 +1,100 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct IdentityConnectedArgs {} + +impl From for super::Reducer { + fn from(args: IdentityConnectedArgs) -> Self { + Self::IdentityConnected + } +} + +impl __sdk::InModule for IdentityConnectedArgs { + type Module = super::RemoteModule; +} + +pub struct IdentityConnectedCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `identity_connected`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait identity_connected { + /// Request that the remote module invoke the reducer `identity_connected` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_identity_connected`] callbacks. + fn identity_connected(&self) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `identity_connected`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`IdentityConnectedCallbackId`] can be passed to [`Self::remove_on_identity_connected`] + /// to cancel the callback. + fn on_identity_connected( + &self, + callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, + ) -> IdentityConnectedCallbackId; + /// Cancel a callback previously registered by [`Self::on_identity_connected`], + /// causing it not to run in the future. + fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId); +} + +impl identity_connected for super::RemoteReducers { + fn identity_connected(&self) -> __sdk::Result<()> { + self.imp.call_reducer("identity_connected", IdentityConnectedArgs {}) + } + fn on_identity_connected( + &self, + mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, + ) -> IdentityConnectedCallbackId { + IdentityConnectedCallbackId(self.imp.on_reducer( + "identity_connected", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::IdentityConnected {}, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx) + }), + )) + } + fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId) { + self.imp.remove_on_reducer("identity_connected", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `identity_connected`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_identity_connected { + /// Set the call-reducer flags for the reducer `identity_connected` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn identity_connected(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_identity_connected for super::SetReducerFlags { + fn identity_connected(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("identity_connected", flags); + } +} diff --git a/templates/basic-rs/src/module_bindings/identity_disconnected_reducer.rs b/templates/basic-rs/src/module_bindings/identity_disconnected_reducer.rs new file mode 100644 index 00000000000..ae4679d09aa --- /dev/null +++ b/templates/basic-rs/src/module_bindings/identity_disconnected_reducer.rs @@ -0,0 +1,101 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct IdentityDisconnectedArgs {} + +impl From for super::Reducer { + fn from(args: IdentityDisconnectedArgs) -> Self { + Self::IdentityDisconnected + } +} + +impl __sdk::InModule for IdentityDisconnectedArgs { + type Module = super::RemoteModule; +} + +pub struct IdentityDisconnectedCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `identity_disconnected`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait identity_disconnected { + /// Request that the remote module invoke the reducer `identity_disconnected` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_identity_disconnected`] callbacks. + fn identity_disconnected(&self) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `identity_disconnected`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`IdentityDisconnectedCallbackId`] can be passed to [`Self::remove_on_identity_disconnected`] + /// to cancel the callback. + fn on_identity_disconnected( + &self, + callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, + ) -> IdentityDisconnectedCallbackId; + /// Cancel a callback previously registered by [`Self::on_identity_disconnected`], + /// causing it not to run in the future. + fn remove_on_identity_disconnected(&self, callback: IdentityDisconnectedCallbackId); +} + +impl identity_disconnected for super::RemoteReducers { + fn identity_disconnected(&self) -> __sdk::Result<()> { + self.imp + .call_reducer("identity_disconnected", IdentityDisconnectedArgs {}) + } + fn on_identity_disconnected( + &self, + mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, + ) -> IdentityDisconnectedCallbackId { + IdentityDisconnectedCallbackId(self.imp.on_reducer( + "identity_disconnected", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::IdentityDisconnected {}, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx) + }), + )) + } + fn remove_on_identity_disconnected(&self, callback: IdentityDisconnectedCallbackId) { + self.imp.remove_on_reducer("identity_disconnected", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `identity_disconnected`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_identity_disconnected { + /// Set the call-reducer flags for the reducer `identity_disconnected` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn identity_disconnected(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_identity_disconnected for super::SetReducerFlags { + fn identity_disconnected(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("identity_disconnected", flags); + } +} diff --git a/templates/basic-rs/src/module_bindings/mod.rs b/templates/basic-rs/src/module_bindings/mod.rs new file mode 100644 index 00000000000..bed32cca871 --- /dev/null +++ b/templates/basic-rs/src/module_bindings/mod.rs @@ -0,0 +1,855 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +// This was generated using spacetimedb cli version 1.11.3 (commit ac10fc10f73238f4f2e937cc30aba3539bf2e4be). + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +pub mod add_reducer; +pub mod identity_connected_reducer; +pub mod identity_disconnected_reducer; +pub mod person_table; +pub mod person_type; +pub mod say_hello_reducer; + +pub use add_reducer::{add, set_flags_for_add, AddCallbackId}; +pub use identity_connected_reducer::{ + identity_connected, set_flags_for_identity_connected, IdentityConnectedCallbackId, +}; +pub use identity_disconnected_reducer::{ + identity_disconnected, set_flags_for_identity_disconnected, IdentityDisconnectedCallbackId, +}; +pub use person_table::*; +pub use person_type::Person; +pub use say_hello_reducer::{say_hello, set_flags_for_say_hello, SayHelloCallbackId}; + +#[derive(Clone, PartialEq, Debug)] + +/// One of the reducers defined by this module. +/// +/// Contained within a [`__sdk::ReducerEvent`] in [`EventContext`]s for reducer events +/// to indicate which reducer caused the event. + +pub enum Reducer { + Add { name: String }, + IdentityConnected, + IdentityDisconnected, + SayHello, +} + +impl __sdk::InModule for Reducer { + type Module = RemoteModule; +} + +impl __sdk::Reducer for Reducer { + fn reducer_name(&self) -> &'static str { + match self { + Reducer::Add { .. } => "add", + Reducer::IdentityConnected => "identity_connected", + Reducer::IdentityDisconnected => "identity_disconnected", + Reducer::SayHello => "say_hello", + _ => unreachable!(), + } + } +} +impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { + type Error = __sdk::Error; + fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result { + match &value.reducer_name[..] { + "add" => Ok(__sdk::parse_reducer_args::("add", &value.args)?.into()), + "identity_connected" => Ok( + __sdk::parse_reducer_args::( + "identity_connected", + &value.args, + )? + .into(), + ), + "identity_disconnected" => Ok(__sdk::parse_reducer_args::< + identity_disconnected_reducer::IdentityDisconnectedArgs, + >("identity_disconnected", &value.args)? + .into()), + "say_hello" => { + Ok(__sdk::parse_reducer_args::("say_hello", &value.args)?.into()) + } + unknown => Err(__sdk::InternalError::unknown_name("reducer", unknown, "ReducerCallInfo").into()), + } + } +} + +#[derive(Default)] +#[allow(non_snake_case)] +#[doc(hidden)] +pub struct DbUpdate { + person: __sdk::TableUpdate, +} + +impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { + type Error = __sdk::Error; + fn try_from(raw: __ws::DatabaseUpdate<__ws::BsatnFormat>) -> Result { + let mut db_update = DbUpdate::default(); + for table_update in raw.tables { + match &table_update.table_name[..] { + "person" => db_update.person.append(person_table::parse_table_update(table_update)?), + + unknown => { + return Err(__sdk::InternalError::unknown_name("table", unknown, "DatabaseUpdate").into()); + } + } + } + Ok(db_update) + } +} + +impl __sdk::InModule for DbUpdate { + type Module = RemoteModule; +} + +impl __sdk::DbUpdate for DbUpdate { + fn apply_to_client_cache(&self, cache: &mut __sdk::ClientCache) -> AppliedDiff<'_> { + let mut diff = AppliedDiff::default(); + + diff.person = cache.apply_diff_to_table::("person", &self.person); + + diff + } +} + +#[derive(Default)] +#[allow(non_snake_case)] +#[doc(hidden)] +pub struct AppliedDiff<'r> { + person: __sdk::TableAppliedDiff<'r, Person>, + __unused: std::marker::PhantomData<&'r ()>, +} + +impl __sdk::InModule for AppliedDiff<'_> { + type Module = RemoteModule; +} + +impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> { + fn invoke_row_callbacks(&self, event: &EventContext, callbacks: &mut __sdk::DbCallbacks) { + callbacks.invoke_table_row_callbacks::("person", &self.person, event); + } +} + +#[doc(hidden)] +pub struct RemoteModule; + +impl __sdk::InModule for RemoteModule { + type Module = Self; +} + +/// The `reducers` field of [`EventContext`] and [`DbConnection`], +/// with methods provided by extension traits for each reducer defined by the module. +pub struct RemoteReducers { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for RemoteReducers { + type Module = RemoteModule; +} + +/// The `procedures` field of [`DbConnection`] and other [`DbContext`] types, +/// with methods provided by extension traits for each procedure defined by the module. +pub struct RemoteProcedures { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for RemoteProcedures { + type Module = RemoteModule; +} + +#[doc(hidden)] +/// The `set_reducer_flags` field of [`DbConnection`], +/// with methods provided by extension traits for each reducer defined by the module. +/// Each method sets the flags for the reducer with the same name. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub struct SetReducerFlags { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for SetReducerFlags { + type Module = RemoteModule; +} + +/// The `db` field of [`EventContext`] and [`DbConnection`], +/// with methods provided by extension traits for each table defined by the module. +pub struct RemoteTables { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for RemoteTables { + type Module = RemoteModule; +} + +/// A connection to a remote module, including a materialized view of a subset of the database. +/// +/// Connect to a remote module by calling [`DbConnection::builder`] +/// and using the [`__sdk::DbConnectionBuilder`] builder-pattern constructor. +/// +/// You must explicitly advance the connection by calling any one of: +/// +/// - [`DbConnection::frame_tick`]. +/// - [`DbConnection::run_threaded`]. +/// - [`DbConnection::run_async`]. +/// - [`DbConnection::advance_one_message`]. +/// - [`DbConnection::advance_one_message_blocking`]. +/// - [`DbConnection::advance_one_message_async`]. +/// +/// Which of these methods you should call depends on the specific needs of your application, +/// but you must call one of them, or else the connection will never progress. +pub struct DbConnection { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + #[doc(hidden)] + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for DbConnection { + type Module = RemoteModule; +} + +impl __sdk::DbContext for DbConnection { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl DbConnection { + /// Builder-pattern constructor for a connection to a remote module. + /// + /// See [`__sdk::DbConnectionBuilder`] for required and optional configuration for the new connection. + pub fn builder() -> __sdk::DbConnectionBuilder { + __sdk::DbConnectionBuilder::new() + } + + /// If any WebSocket messages are waiting, process one of them. + /// + /// Returns `true` if a message was processed, or `false` if the queue is empty. + /// Callers should invoke this message in a loop until it returns `false` + /// or for as much time is available to process messages. + /// + /// Returns an error if the connection is disconnected. + /// If the disconnection in question was normal, + /// i.e. the result of a call to [`__sdk::DbContext::disconnect`], + /// the returned error will be downcastable to [`__sdk::DisconnectedError`]. + /// + /// This is a low-level primitive exposed for power users who need significant control over scheduling. + /// Most applications should call [`Self::frame_tick`] each frame + /// to fully exhaust the queue whenever time is available. + pub fn advance_one_message(&self) -> __sdk::Result { + self.imp.advance_one_message() + } + + /// Process one WebSocket message, potentially blocking the current thread until one is received. + /// + /// Returns an error if the connection is disconnected. + /// If the disconnection in question was normal, + /// i.e. the result of a call to [`__sdk::DbContext::disconnect`], + /// the returned error will be downcastable to [`__sdk::DisconnectedError`]. + /// + /// This is a low-level primitive exposed for power users who need significant control over scheduling. + /// Most applications should call [`Self::run_threaded`] to spawn a thread + /// which advances the connection automatically. + pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> { + self.imp.advance_one_message_blocking() + } + + /// Process one WebSocket message, `await`ing until one is received. + /// + /// Returns an error if the connection is disconnected. + /// If the disconnection in question was normal, + /// i.e. the result of a call to [`__sdk::DbContext::disconnect`], + /// the returned error will be downcastable to [`__sdk::DisconnectedError`]. + /// + /// This is a low-level primitive exposed for power users who need significant control over scheduling. + /// Most applications should call [`Self::run_async`] to run an `async` loop + /// which advances the connection when polled. + pub async fn advance_one_message_async(&self) -> __sdk::Result<()> { + self.imp.advance_one_message_async().await + } + + /// Process all WebSocket messages waiting in the queue, + /// then return without `await`ing or blocking the current thread. + pub fn frame_tick(&self) -> __sdk::Result<()> { + self.imp.frame_tick() + } + + /// Spawn a thread which processes WebSocket messages as they are received. + pub fn run_threaded(&self) -> std::thread::JoinHandle<()> { + self.imp.run_threaded() + } + + /// Run an `async` loop which processes WebSocket messages when polled. + pub async fn run_async(&self) -> __sdk::Result<()> { + self.imp.run_async().await + } +} + +impl __sdk::DbConnection for DbConnection { + fn new(imp: __sdk::DbContextImpl) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + imp, + } + } +} + +/// A handle on a subscribed query. +// TODO: Document this better after implementing the new subscription API. +#[derive(Clone)] +pub struct SubscriptionHandle { + imp: __sdk::SubscriptionHandleImpl, +} + +impl __sdk::InModule for SubscriptionHandle { + type Module = RemoteModule; +} + +impl __sdk::SubscriptionHandle for SubscriptionHandle { + fn new(imp: __sdk::SubscriptionHandleImpl) -> Self { + Self { imp } + } + + /// Returns true if this subscription has been terminated due to an unsubscribe call or an error. + fn is_ended(&self) -> bool { + self.imp.is_ended() + } + + /// Returns true if this subscription has been applied and has not yet been unsubscribed. + fn is_active(&self) -> bool { + self.imp.is_active() + } + + /// Unsubscribe from the query controlled by this `SubscriptionHandle`, + /// then run `on_end` when its rows are removed from the client cache. + fn unsubscribe_then(self, on_end: __sdk::OnEndedCallback) -> __sdk::Result<()> { + self.imp.unsubscribe_then(Some(on_end)) + } + + fn unsubscribe(self) -> __sdk::Result<()> { + self.imp.unsubscribe_then(None) + } +} + +/// Alias trait for a [`__sdk::DbContext`] connected to this module, +/// with that trait's associated types bounded to this module's concrete types. +/// +/// Users can use this trait as a boundary on definitions which should accept +/// either a [`DbConnection`] or an [`EventContext`] and operate on either. +pub trait RemoteDbContext: + __sdk::DbContext< + DbView = RemoteTables, + Reducers = RemoteReducers, + SetReducerFlags = SetReducerFlags, + SubscriptionBuilder = __sdk::SubscriptionBuilder, +> +{ +} +impl< + Ctx: __sdk::DbContext< + DbView = RemoteTables, + Reducers = RemoteReducers, + SetReducerFlags = SetReducerFlags, + SubscriptionBuilder = __sdk::SubscriptionBuilder, + >, + > RemoteDbContext for Ctx +{ +} + +/// An [`__sdk::DbContext`] augmented with a [`__sdk::Event`], +/// passed to [`__sdk::Table::on_insert`], [`__sdk::Table::on_delete`] and [`__sdk::TableWithPrimaryKey::on_update`] callbacks. +pub struct EventContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + /// The event which caused these callbacks to run. + pub event: __sdk::Event, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for EventContext { + type Event = __sdk::Event; + fn event(&self) -> &Self::Event { + &self.event + } + fn new(imp: __sdk::DbContextImpl, event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + event, + imp, + } + } +} + +impl __sdk::InModule for EventContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for EventContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::EventContext for EventContext {} + +/// An [`__sdk::DbContext`] augmented with a [`__sdk::ReducerEvent`], +/// passed to on-reducer callbacks. +pub struct ReducerEventContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + /// The event which caused these callbacks to run. + pub event: __sdk::ReducerEvent, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for ReducerEventContext { + type Event = __sdk::ReducerEvent; + fn event(&self) -> &Self::Event { + &self.event + } + fn new(imp: __sdk::DbContextImpl, event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + event, + imp, + } + } +} + +impl __sdk::InModule for ReducerEventContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for ReducerEventContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::ReducerEventContext for ReducerEventContext {} + +/// An [`__sdk::DbContext`] passed to procedure callbacks. +pub struct ProcedureEventContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for ProcedureEventContext { + type Event = (); + fn event(&self) -> &Self::Event { + &() + } + fn new(imp: __sdk::DbContextImpl, _event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + imp, + } + } +} + +impl __sdk::InModule for ProcedureEventContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for ProcedureEventContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::ProcedureEventContext for ProcedureEventContext {} + +/// An [`__sdk::DbContext`] passed to [`__sdk::SubscriptionBuilder::on_applied`] and [`SubscriptionHandle::unsubscribe_then`] callbacks. +pub struct SubscriptionEventContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for SubscriptionEventContext { + type Event = (); + fn event(&self) -> &Self::Event { + &() + } + fn new(imp: __sdk::DbContextImpl, _event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + imp, + } + } +} + +impl __sdk::InModule for SubscriptionEventContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for SubscriptionEventContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::SubscriptionEventContext for SubscriptionEventContext {} + +/// An [`__sdk::DbContext`] augmented with a [`__sdk::Error`], +/// passed to [`__sdk::DbConnectionBuilder::on_disconnect`], [`__sdk::DbConnectionBuilder::on_connect_error`] and [`__sdk::SubscriptionBuilder::on_error`] callbacks. +pub struct ErrorContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + /// The event which caused these callbacks to run. + pub event: Option<__sdk::Error>, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for ErrorContext { + type Event = Option<__sdk::Error>; + fn event(&self) -> &Self::Event { + &self.event + } + fn new(imp: __sdk::DbContextImpl, event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + event, + imp, + } + } +} + +impl __sdk::InModule for ErrorContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for ErrorContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::ErrorContext for ErrorContext {} + +impl __sdk::SpacetimeModule for RemoteModule { + type DbConnection = DbConnection; + type EventContext = EventContext; + type ReducerEventContext = ReducerEventContext; + type ProcedureEventContext = ProcedureEventContext; + type SubscriptionEventContext = SubscriptionEventContext; + type ErrorContext = ErrorContext; + type Reducer = Reducer; + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type SetReducerFlags = SetReducerFlags; + type DbUpdate = DbUpdate; + type AppliedDiff<'r> = AppliedDiff<'r>; + type SubscriptionHandle = SubscriptionHandle; + type QueryBuilder = __sdk::QueryBuilder; + + fn register_tables(client_cache: &mut __sdk::ClientCache) { + person_table::register_table(client_cache); + } +} diff --git a/templates/basic-rs/src/module_bindings/person_table.rs b/templates/basic-rs/src/module_bindings/person_table.rs new file mode 100644 index 00000000000..07d0c75a46c --- /dev/null +++ b/templates/basic-rs/src/module_bindings/person_table.rs @@ -0,0 +1,111 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::person_type::Person; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `person`. +/// +/// Obtain a handle from the [`PersonTableAccess::person`] method on [`super::RemoteTables`], +/// like `ctx.db.person()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.person().on_insert(...)`. +pub struct PersonTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `person`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait PersonTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`PersonTableHandle`], which mediates access to the table `person`. + fn person(&self) -> PersonTableHandle<'_>; +} + +impl PersonTableAccess for super::RemoteTables { + fn person(&self) -> PersonTableHandle<'_> { + PersonTableHandle { + imp: self.imp.get_table::("person"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct PersonInsertCallbackId(__sdk::CallbackId); +pub struct PersonDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for PersonTableHandle<'ctx> { + type Row = Person; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = PersonInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> PersonInsertCallbackId { + PersonInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: PersonInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = PersonDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> PersonDeleteCallbackId { + PersonDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: PersonDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("person"); +} + +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `Person`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait personQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `Person`. + fn person(&self) -> __sdk::__query_builder::Table; +} + +impl personQueryTableAccess for __sdk::QueryTableAccessor { + fn person(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("person") + } +} diff --git a/templates/basic-rs/src/module_bindings/person_type.rs b/templates/basic-rs/src/module_bindings/person_type.rs new file mode 100644 index 00000000000..7601bdf9114 --- /dev/null +++ b/templates/basic-rs/src/module_bindings/person_type.rs @@ -0,0 +1,43 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub struct Person { + pub name: String, +} + +impl __sdk::InModule for Person { + type Module = super::RemoteModule; +} + +/// Column accessor struct for the table `Person`. +/// +/// Provides typed access to columns for query building. +pub struct PersonCols { + pub name: __sdk::__query_builder::Col, +} + +impl __sdk::__query_builder::HasCols for Person { + type Cols = PersonCols; + fn cols(table_name: &'static str) -> Self::Cols { + PersonCols { + name: __sdk::__query_builder::Col::new(table_name, "name"), + } + } +} + +/// Indexed column accessor struct for the table `Person`. +/// +/// Provides typed access to indexed columns for query building. +pub struct PersonIxCols {} + +impl __sdk::__query_builder::HasIxCols for Person { + type IxCols = PersonIxCols; + fn ix_cols(table_name: &'static str) -> Self::IxCols { + PersonIxCols {} + } +} diff --git a/templates/basic-rs/src/module_bindings/say_hello_reducer.rs b/templates/basic-rs/src/module_bindings/say_hello_reducer.rs new file mode 100644 index 00000000000..c3b8c277050 --- /dev/null +++ b/templates/basic-rs/src/module_bindings/say_hello_reducer.rs @@ -0,0 +1,97 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] +#[sats(crate = __lib)] +pub(super) struct SayHelloArgs {} + +impl From for super::Reducer { + fn from(args: SayHelloArgs) -> Self { + Self::SayHello + } +} + +impl __sdk::InModule for SayHelloArgs { + type Module = super::RemoteModule; +} + +pub struct SayHelloCallbackId(__sdk::CallbackId); + +#[allow(non_camel_case_types)] +/// Extension trait for access to the reducer `say_hello`. +/// +/// Implemented for [`super::RemoteReducers`]. +pub trait say_hello { + /// Request that the remote module invoke the reducer `say_hello` to run as soon as possible. + /// + /// This method returns immediately, and errors only if we are unable to send the request. + /// The reducer will run asynchronously in the future, + /// and its status can be observed by listening for [`Self::on_say_hello`] callbacks. + fn say_hello(&self) -> __sdk::Result<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `say_hello`. + /// + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`SayHelloCallbackId`] can be passed to [`Self::remove_on_say_hello`] + /// to cancel the callback. + fn on_say_hello(&self, callback: impl FnMut(&super::ReducerEventContext) + Send + 'static) -> SayHelloCallbackId; + /// Cancel a callback previously registered by [`Self::on_say_hello`], + /// causing it not to run in the future. + fn remove_on_say_hello(&self, callback: SayHelloCallbackId); +} + +impl say_hello for super::RemoteReducers { + fn say_hello(&self) -> __sdk::Result<()> { + self.imp.call_reducer("say_hello", SayHelloArgs {}) + } + fn on_say_hello( + &self, + mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static, + ) -> SayHelloCallbackId { + SayHelloCallbackId(self.imp.on_reducer( + "say_hello", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::SayHello {}, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx) + }), + )) + } + fn remove_on_say_hello(&self, callback: SayHelloCallbackId) { + self.imp.remove_on_reducer("say_hello", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `say_hello`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_say_hello { + /// Set the call-reducer flags for the reducer `say_hello` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn say_hello(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_say_hello for super::SetReducerFlags { + fn say_hello(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("say_hello", flags); + } +} diff --git a/templates/basic-ts/src/module_bindings/index.ts b/templates/basic-ts/src/module_bindings/index.ts index 23ea2b9deb3..f3670cefe37 100644 --- a/templates/basic-ts/src/module_bindings/index.ts +++ b/templates/basic-ts/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.3 (commit f9bca6a8df856d950360b40cbce744fcbffc9a63). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -87,7 +87,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.3' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, diff --git a/templates/chat-console-cs/module_bindings/SpacetimeDBClient.g.cs b/templates/chat-console-cs/module_bindings/SpacetimeDBClient.g.cs index eaca76ff731..a5faff28232 100644 --- a/templates/chat-console-cs/module_bindings/SpacetimeDBClient.g.cs +++ b/templates/chat-console-cs/module_bindings/SpacetimeDBClient.g.cs @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.2 (commit 97aa69de8942102a6ea0b50dfadea3cd15e44f50). +// This was generated using spacetimedb cli version 1.11.3 (commit ac10fc10f73238f4f2e937cc30aba3539bf2e4be). #nullable enable @@ -582,8 +582,8 @@ public sealed class QueryBuilder public sealed class From { - public global::SpacetimeDB.Table Message() => new("message", new MessageCols("message"), new MessageIxCols("message")); - public global::SpacetimeDB.Table User() => new("user", new UserCols("user"), new UserIxCols("user")); + public global::SpacetimeDB.Table Message() => new("Message", new MessageCols("Message"), new MessageIxCols("Message")); + public global::SpacetimeDB.Table User() => new("User", new UserCols("User"), new UserIxCols("User")); } public sealed class TypedSubscriptionBuilder @@ -615,7 +615,7 @@ public TypedSubscriptionBuilder OnError(Action callback public TypedSubscriptionBuilder AddQuery(Func> build) { var qb = new QueryBuilder(); - querySqls.Add(build(qb).Sql); + querySqls.Add(build(qb).ToSql()); return this; } diff --git a/templates/chat-console-cs/module_bindings/Tables/Message.g.cs b/templates/chat-console-cs/module_bindings/Tables/Message.g.cs index e66dab667b9..a21ee4d37f6 100644 --- a/templates/chat-console-cs/module_bindings/Tables/Message.g.cs +++ b/templates/chat-console-cs/module_bindings/Tables/Message.g.cs @@ -15,7 +15,7 @@ public sealed partial class RemoteTables { public sealed class MessageHandle : RemoteTableHandle { - protected override string RemoteTableName => "message"; + protected override string RemoteTableName => "Message"; internal MessageHandle(DbConnection conn) : base(conn) { diff --git a/templates/chat-console-cs/module_bindings/Tables/User.g.cs b/templates/chat-console-cs/module_bindings/Tables/User.g.cs index b9043dc9cf2..43ef4f78e03 100644 --- a/templates/chat-console-cs/module_bindings/Tables/User.g.cs +++ b/templates/chat-console-cs/module_bindings/Tables/User.g.cs @@ -15,7 +15,7 @@ public sealed partial class RemoteTables { public sealed class UserHandle : RemoteTableHandle { - protected override string RemoteTableName => "user"; + protected override string RemoteTableName => "User"; public sealed class IdentityUniqueIndex : UniqueIndexBase { @@ -40,13 +40,13 @@ internal UserHandle(DbConnection conn) : base(conn) public sealed class UserCols { public global::SpacetimeDB.Col Identity { get; } - public global::SpacetimeDB.Col Name { get; } + public global::SpacetimeDB.NullableCol Name { get; } public global::SpacetimeDB.Col Online { get; } public UserCols(string tableName) { Identity = new global::SpacetimeDB.Col(tableName, "Identity"); - Name = new global::SpacetimeDB.Col(tableName, "Name"); + Name = new global::SpacetimeDB.NullableCol(tableName, "Name"); Online = new global::SpacetimeDB.Col(tableName, "Online"); } } diff --git a/templates/chat-console-rs/src/module_bindings/identity_connected_reducer.rs b/templates/chat-console-rs/src/module_bindings/identity_connected_reducer.rs index 0696aa16ccc..5c2d5e0df4e 100644 --- a/templates/chat-console-rs/src/module_bindings/identity_connected_reducer.rs +++ b/templates/chat-console-rs/src/module_bindings/identity_connected_reducer.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -60,6 +58,7 @@ impl identity_connected for super::RemoteReducers { IdentityConnectedCallbackId(self.imp.on_reducer( "identity_connected", Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] let super::ReducerEventContext { event: __sdk::ReducerEvent { diff --git a/templates/chat-console-rs/src/module_bindings/identity_disconnected_reducer.rs b/templates/chat-console-rs/src/module_bindings/identity_disconnected_reducer.rs index 23831f6473f..ae4679d09aa 100644 --- a/templates/chat-console-rs/src/module_bindings/identity_disconnected_reducer.rs +++ b/templates/chat-console-rs/src/module_bindings/identity_disconnected_reducer.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -61,6 +59,7 @@ impl identity_disconnected for super::RemoteReducers { IdentityDisconnectedCallbackId(self.imp.on_reducer( "identity_disconnected", Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] let super::ReducerEventContext { event: __sdk::ReducerEvent { diff --git a/templates/chat-console-rs/src/module_bindings/message_table.rs b/templates/chat-console-rs/src/module_bindings/message_table.rs index fcd4908abb3..9d5595742ea 100644 --- a/templates/chat-console-rs/src/module_bindings/message_table.rs +++ b/templates/chat-console-rs/src/module_bindings/message_table.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use super::message_type::Message; use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -95,3 +93,19 @@ pub(super) fn parse_table_update( .into() }) } + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `Message`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait messageQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `Message`. + fn message(&self) -> __sdk::__query_builder::Table; +} + +impl messageQueryTableAccess for __sdk::QueryTableAccessor { + fn message(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("message") + } +} diff --git a/templates/chat-console-rs/src/module_bindings/message_type.rs b/templates/chat-console-rs/src/module_bindings/message_type.rs index 184c9520f6f..0d60be134e9 100644 --- a/templates/chat-console-rs/src/module_bindings/message_type.rs +++ b/templates/chat-console-rs/src/module_bindings/message_type.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -17,3 +15,35 @@ pub struct Message { impl __sdk::InModule for Message { type Module = super::RemoteModule; } + +/// Column accessor struct for the table `Message`. +/// +/// Provides typed access to columns for query building. +pub struct MessageCols { + pub sender: __sdk::__query_builder::Col, + pub sent: __sdk::__query_builder::Col, + pub text: __sdk::__query_builder::Col, +} + +impl __sdk::__query_builder::HasCols for Message { + type Cols = MessageCols; + fn cols(table_name: &'static str) -> Self::Cols { + MessageCols { + sender: __sdk::__query_builder::Col::new(table_name, "sender"), + sent: __sdk::__query_builder::Col::new(table_name, "sent"), + text: __sdk::__query_builder::Col::new(table_name, "text"), + } + } +} + +/// Indexed column accessor struct for the table `Message`. +/// +/// Provides typed access to indexed columns for query building. +pub struct MessageIxCols {} + +impl __sdk::__query_builder::HasIxCols for Message { + type IxCols = MessageIxCols; + fn ix_cols(table_name: &'static str) -> Self::IxCols { + MessageIxCols {} + } +} diff --git a/templates/chat-console-rs/src/module_bindings/mod.rs b/templates/chat-console-rs/src/module_bindings/mod.rs index 3497ccdc4e1..54820ea5fa5 100644 --- a/templates/chat-console-rs/src/module_bindings/mod.rs +++ b/templates/chat-console-rs/src/module_bindings/mod.rs @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). +// This was generated using spacetimedb cli version 1.11.3 (commit ac10fc10f73238f4f2e937cc30aba3539bf2e4be). #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -53,6 +53,7 @@ impl __sdk::Reducer for Reducer { Reducer::IdentityDisconnected => "identity_disconnected", Reducer::SendMessage { .. } => "send_message", Reducer::SetName { .. } => "set_name", + _ => unreachable!(), } } } @@ -135,6 +136,7 @@ impl __sdk::DbUpdate for DbUpdate { pub struct AppliedDiff<'r> { message: __sdk::TableAppliedDiff<'r, Message>, user: __sdk::TableAppliedDiff<'r, User>, + __unused: std::marker::PhantomData<&'r ()>, } impl __sdk::InModule for AppliedDiff<'_> { @@ -165,6 +167,16 @@ impl __sdk::InModule for RemoteReducers { type Module = RemoteModule; } +/// The `procedures` field of [`DbConnection`] and other [`DbContext`] types, +/// with methods provided by extension traits for each procedure defined by the module. +pub struct RemoteProcedures { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for RemoteProcedures { + type Module = RemoteModule; +} + #[doc(hidden)] /// The `set_reducer_flags` field of [`DbConnection`], /// with methods provided by extension traits for each reducer defined by the module. @@ -217,6 +229,9 @@ pub struct DbConnection { /// This type is currently unstable and may be removed without a major version bump. pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + imp: __sdk::DbContextImpl, } @@ -227,6 +242,7 @@ impl __sdk::InModule for DbConnection { impl __sdk::DbContext for DbConnection { type DbView = RemoteTables; type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { @@ -235,6 +251,9 @@ impl __sdk::DbContext for DbConnection { fn reducers(&self) -> &Self::Reducers { &self.reducers } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } fn set_reducer_flags(&self) -> &Self::SetReducerFlags { &self.set_reducer_flags } @@ -340,6 +359,7 @@ impl __sdk::DbConnection for DbConnection { Self { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, set_reducer_flags: SetReducerFlags { imp: imp.clone() }, imp, } @@ -420,6 +440,8 @@ pub struct EventContext { /// /// This type is currently unstable and may be removed without a major version bump. pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. pub event: __sdk::Event, imp: __sdk::DbContextImpl, @@ -435,6 +457,7 @@ impl __sdk::AbstractEventContext for EventContext { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, event, imp, } @@ -448,6 +471,7 @@ impl __sdk::InModule for EventContext { impl __sdk::DbContext for EventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { @@ -456,6 +480,9 @@ impl __sdk::DbContext for EventContext { fn reducers(&self) -> &Self::Reducers { &self.reducers } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } fn set_reducer_flags(&self) -> &Self::SetReducerFlags { &self.set_reducer_flags } @@ -499,6 +526,8 @@ pub struct ReducerEventContext { /// /// This type is currently unstable and may be removed without a major version bump. pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. pub event: __sdk::ReducerEvent, imp: __sdk::DbContextImpl, @@ -514,6 +543,7 @@ impl __sdk::AbstractEventContext for ReducerEventContext { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, event, imp, } @@ -527,6 +557,7 @@ impl __sdk::InModule for ReducerEventContext { impl __sdk::DbContext for ReducerEventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { @@ -535,6 +566,9 @@ impl __sdk::DbContext for ReducerEventContext { fn reducers(&self) -> &Self::Reducers { &self.reducers } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } fn set_reducer_flags(&self) -> &Self::SetReducerFlags { &self.set_reducer_flags } @@ -566,6 +600,88 @@ impl __sdk::DbContext for ReducerEventContext { impl __sdk::ReducerEventContext for ReducerEventContext {} +/// An [`__sdk::DbContext`] passed to procedure callbacks. +pub struct ProcedureEventContext { + /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. + pub db: RemoteTables, + /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. + pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, + imp: __sdk::DbContextImpl, +} + +impl __sdk::AbstractEventContext for ProcedureEventContext { + type Event = (); + fn event(&self) -> &Self::Event { + &() + } + fn new(imp: __sdk::DbContextImpl, _event: Self::Event) -> Self { + Self { + db: RemoteTables { imp: imp.clone() }, + reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + imp, + } + } +} + +impl __sdk::InModule for ProcedureEventContext { + type Module = RemoteModule; +} + +impl __sdk::DbContext for ProcedureEventContext { + type DbView = RemoteTables; + type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; + + fn db(&self) -> &Self::DbView { + &self.db + } + fn reducers(&self) -> &Self::Reducers { + &self.reducers + } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } + + fn is_active(&self) -> bool { + self.imp.is_active() + } + + fn disconnect(&self) -> __sdk::Result<()> { + self.imp.disconnect() + } + + type SubscriptionBuilder = __sdk::SubscriptionBuilder; + + fn subscription_builder(&self) -> Self::SubscriptionBuilder { + __sdk::SubscriptionBuilder::new(&self.imp) + } + + fn try_identity(&self) -> Option<__sdk::Identity> { + self.imp.try_identity() + } + fn connection_id(&self) -> __sdk::ConnectionId { + self.imp.connection_id() + } + fn try_connection_id(&self) -> Option<__sdk::ConnectionId> { + self.imp.try_connection_id() + } +} + +impl __sdk::ProcedureEventContext for ProcedureEventContext {} + /// An [`__sdk::DbContext`] passed to [`__sdk::SubscriptionBuilder::on_applied`] and [`SubscriptionHandle::unsubscribe_then`] callbacks. pub struct SubscriptionEventContext { /// Access to tables defined by the module via extension traits implemented for [`RemoteTables`]. @@ -577,6 +693,8 @@ pub struct SubscriptionEventContext { /// /// This type is currently unstable and may be removed without a major version bump. pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, imp: __sdk::DbContextImpl, } @@ -589,6 +707,7 @@ impl __sdk::AbstractEventContext for SubscriptionEventContext { Self { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, set_reducer_flags: SetReducerFlags { imp: imp.clone() }, imp, } @@ -602,6 +721,7 @@ impl __sdk::InModule for SubscriptionEventContext { impl __sdk::DbContext for SubscriptionEventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { @@ -610,6 +730,9 @@ impl __sdk::DbContext for SubscriptionEventContext { fn reducers(&self) -> &Self::Reducers { &self.reducers } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } fn set_reducer_flags(&self) -> &Self::SetReducerFlags { &self.set_reducer_flags } @@ -653,6 +776,8 @@ pub struct ErrorContext { /// /// This type is currently unstable and may be removed without a major version bump. pub set_reducer_flags: SetReducerFlags, + /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. + pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. pub event: Option<__sdk::Error>, imp: __sdk::DbContextImpl, @@ -668,6 +793,7 @@ impl __sdk::AbstractEventContext for ErrorContext { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, set_reducer_flags: SetReducerFlags { imp: imp.clone() }, + procedures: RemoteProcedures { imp: imp.clone() }, event, imp, } @@ -681,6 +807,7 @@ impl __sdk::InModule for ErrorContext { impl __sdk::DbContext for ErrorContext { type DbView = RemoteTables; type Reducers = RemoteReducers; + type Procedures = RemoteProcedures; type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { @@ -689,6 +816,9 @@ impl __sdk::DbContext for ErrorContext { fn reducers(&self) -> &Self::Reducers { &self.reducers } + fn procedures(&self) -> &Self::Procedures { + &self.procedures + } fn set_reducer_flags(&self) -> &Self::SetReducerFlags { &self.set_reducer_flags } @@ -724,6 +854,7 @@ impl __sdk::SpacetimeModule for RemoteModule { type DbConnection = DbConnection; type EventContext = EventContext; type ReducerEventContext = ReducerEventContext; + type ProcedureEventContext = ProcedureEventContext; type SubscriptionEventContext = SubscriptionEventContext; type ErrorContext = ErrorContext; type Reducer = Reducer; @@ -733,6 +864,7 @@ impl __sdk::SpacetimeModule for RemoteModule { type DbUpdate = DbUpdate; type AppliedDiff<'r> = AppliedDiff<'r>; type SubscriptionHandle = SubscriptionHandle; + type QueryBuilder = __sdk::QueryBuilder; fn register_tables(client_cache: &mut __sdk::ClientCache) { message_table::register_table(client_cache); diff --git a/templates/chat-console-rs/src/module_bindings/send_message_reducer.rs b/templates/chat-console-rs/src/module_bindings/send_message_reducer.rs index f71342e3b78..e1e701b9e03 100644 --- a/templates/chat-console-rs/src/module_bindings/send_message_reducer.rs +++ b/templates/chat-console-rs/src/module_bindings/send_message_reducer.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -62,6 +60,7 @@ impl send_message for super::RemoteReducers { SendMessageCallbackId(self.imp.on_reducer( "send_message", Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] let super::ReducerEventContext { event: __sdk::ReducerEvent { diff --git a/templates/chat-console-rs/src/module_bindings/set_name_reducer.rs b/templates/chat-console-rs/src/module_bindings/set_name_reducer.rs index 21cd2e1c094..cc9905d3dc1 100644 --- a/templates/chat-console-rs/src/module_bindings/set_name_reducer.rs +++ b/templates/chat-console-rs/src/module_bindings/set_name_reducer.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -62,6 +60,7 @@ impl set_name for super::RemoteReducers { SetNameCallbackId(self.imp.on_reducer( "set_name", Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] let super::ReducerEventContext { event: __sdk::ReducerEvent { diff --git a/templates/chat-console-rs/src/module_bindings/user_table.rs b/templates/chat-console-rs/src/module_bindings/user_table.rs index 130e605272e..efcce134c49 100644 --- a/templates/chat-console-rs/src/module_bindings/user_table.rs +++ b/templates/chat-console-rs/src/module_bindings/user_table.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use super::user_type::User; use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -142,3 +140,19 @@ impl<'ctx> UserIdentityUnique<'ctx> { self.imp.find(col_val) } } + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `User`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait userQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `User`. + fn user(&self) -> __sdk::__query_builder::Table; +} + +impl userQueryTableAccess for __sdk::QueryTableAccessor { + fn user(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("user") + } +} diff --git a/templates/chat-console-rs/src/module_bindings/user_type.rs b/templates/chat-console-rs/src/module_bindings/user_type.rs index 0f453ae68f6..e3de10937b8 100644 --- a/templates/chat-console-rs/src/module_bindings/user_type.rs +++ b/templates/chat-console-rs/src/module_bindings/user_type.rs @@ -1,8 +1,6 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.2.0 (commit 88dc3695d8bc55c081db4a5646a4968da7587405). - #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -17,3 +15,39 @@ pub struct User { impl __sdk::InModule for User { type Module = super::RemoteModule; } + +/// Column accessor struct for the table `User`. +/// +/// Provides typed access to columns for query building. +pub struct UserCols { + pub identity: __sdk::__query_builder::Col, + pub name: __sdk::__query_builder::Col>, + pub online: __sdk::__query_builder::Col, +} + +impl __sdk::__query_builder::HasCols for User { + type Cols = UserCols; + fn cols(table_name: &'static str) -> Self::Cols { + UserCols { + identity: __sdk::__query_builder::Col::new(table_name, "identity"), + name: __sdk::__query_builder::Col::new(table_name, "name"), + online: __sdk::__query_builder::Col::new(table_name, "online"), + } + } +} + +/// Indexed column accessor struct for the table `User`. +/// +/// Provides typed access to indexed columns for query building. +pub struct UserIxCols { + pub identity: __sdk::__query_builder::IxCol, +} + +impl __sdk::__query_builder::HasIxCols for User { + type IxCols = UserIxCols; + fn ix_cols(table_name: &'static str) -> Self::IxCols { + UserIxCols { + identity: __sdk::__query_builder::IxCol::new(table_name, "identity"), + } + } +} diff --git a/templates/chat-react-ts/src/module_bindings/index.ts b/templates/chat-react-ts/src/module_bindings/index.ts index 8d00c314360..6d957c3df8c 100644 --- a/templates/chat-react-ts/src/module_bindings/index.ts +++ b/templates/chat-react-ts/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.12.0 (commit 4a6228fec73c9fefa0ee32ceebf06c91933453ab). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ diff --git a/templates/react-ts/src/module_bindings/index.ts b/templates/react-ts/src/module_bindings/index.ts index 23ea2b9deb3..f3670cefe37 100644 --- a/templates/react-ts/src/module_bindings/index.ts +++ b/templates/react-ts/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.3 (commit f9bca6a8df856d950360b40cbce744fcbffc9a63). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -87,7 +87,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.3' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, diff --git a/templates/svelte-ts/src/module_bindings/index.ts b/templates/svelte-ts/src/module_bindings/index.ts index d726335a186..f3670cefe37 100644 --- a/templates/svelte-ts/src/module_bindings/index.ts +++ b/templates/svelte-ts/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.3 (commit 02449737ca3b29e7e39679fccbef541a50f32094). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -12,6 +12,7 @@ import { TypeBuilder as __TypeBuilder, Uuid as __Uuid, convertToAccessorMap as __convertToAccessorMap, + makeQueryBuilder as __makeQueryBuilder, procedureSchema as __procedureSchema, procedures as __procedures, reducerSchema as __reducerSchema, @@ -25,6 +26,7 @@ import { type Event as __Event, type EventContextInterface as __EventContextInterface, type Infer as __Infer, + type QueryBuilder as __QueryBuilder, type ReducerEventContextInterface as __ReducerEventContextInterface, type RemoteModule as __RemoteModule, type SubscriptionEventContextInterface as __SubscriptionEventContextInterface, @@ -85,7 +87,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.3' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, @@ -99,6 +101,10 @@ const REMOTE_MODULE = { /** The tables available in this remote SpacetimeDB module. */ export const tables = __convertToAccessorMap(tablesSchema.schemaType.tables); +/** A typed query builder for this remote SpacetimeDB module. */ +export const query: __QueryBuilder = + __makeQueryBuilder(tablesSchema.schemaType); + /** The reducers available in this remote SpacetimeDB module. */ export const reducers = __convertToAccessorMap( reducersSchema.reducersType.reducers diff --git a/templates/vue-ts/src/module_bindings/index.ts b/templates/vue-ts/src/module_bindings/index.ts index 3c2919c1917..f3670cefe37 100644 --- a/templates/vue-ts/src/module_bindings/index.ts +++ b/templates/vue-ts/src/module_bindings/index.ts @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 1.11.2 (commit 5508f620e2fd5a4d8a3b7aaf5303776d127f5cbd). +// This was generated using spacetimedb cli version 1.12.0 (commit 441c35afe01b6489e66b4d76be9e52c743c81803). /* eslint-disable */ /* tslint:disable */ @@ -12,6 +12,7 @@ import { TypeBuilder as __TypeBuilder, Uuid as __Uuid, convertToAccessorMap as __convertToAccessorMap, + makeQueryBuilder as __makeQueryBuilder, procedureSchema as __procedureSchema, procedures as __procedures, reducerSchema as __reducerSchema, @@ -25,6 +26,7 @@ import { type Event as __Event, type EventContextInterface as __EventContextInterface, type Infer as __Infer, + type QueryBuilder as __QueryBuilder, type ReducerEventContextInterface as __ReducerEventContextInterface, type RemoteModule as __RemoteModule, type SubscriptionEventContextInterface as __SubscriptionEventContextInterface, @@ -85,7 +87,7 @@ const proceduresSchema = __procedures(); /** The remote SpacetimeDB module schema, both runtime and type information. */ const REMOTE_MODULE = { versionInfo: { - cliVersion: '1.11.2' as const, + cliVersion: '1.12.0' as const, }, tables: tablesSchema.schemaType.tables, reducers: reducersSchema.reducersType.reducers, @@ -99,6 +101,10 @@ const REMOTE_MODULE = { /** The tables available in this remote SpacetimeDB module. */ export const tables = __convertToAccessorMap(tablesSchema.schemaType.tables); +/** A typed query builder for this remote SpacetimeDB module. */ +export const query: __QueryBuilder = + __makeQueryBuilder(tablesSchema.schemaType); + /** The reducers available in this remote SpacetimeDB module. */ export const reducers = __convertToAccessorMap( reducersSchema.reducersType.reducers