-
Notifications
You must be signed in to change notification settings - Fork 1k
[NS 1] Add sub-module mounts support + codegen #5167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alessandro/namespace-base-branch
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // 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 codegen. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <optional> | ||
| #include <memory> | ||
| #include "../autogen_base.h" | ||
| #include "spacetimedb/bsatn/bsatn.h" | ||
|
|
||
| namespace SpacetimeDB::Internal { | ||
| struct RawModuleDefV10; | ||
| } // namespace SpacetimeDB::Internal | ||
|
|
||
| namespace SpacetimeDB::Internal { | ||
|
|
||
| SPACETIMEDB_INTERNAL_PRODUCT_TYPE(RawModuleMountV10) { | ||
| std::string namespace_; | ||
| std::shared_ptr<SpacetimeDB::Internal::RawModuleDefV10> module; | ||
|
|
||
| void bsatn_serialize(::SpacetimeDB::bsatn::Writer& writer) const { | ||
| ::SpacetimeDB::bsatn::serialize(writer, namespace_); | ||
| ::SpacetimeDB::bsatn::serialize(writer, *module); | ||
| } | ||
| SPACETIMEDB_PRODUCT_TYPE_EQUALITY(namespace_, module) | ||
| }; | ||
| } // namespace SpacetimeDB::Internal |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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 codegen. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <optional> | ||
| #include <memory> | ||
| #include "../autogen_base.h" | ||
| #include "spacetimedb/bsatn/bsatn.h" | ||
|
|
||
| namespace SpacetimeDB::Internal { | ||
|
|
||
| SPACETIMEDB_INTERNAL_PRODUCT_TYPE(RawViewPrimaryKeyDefV10) { | ||
| std::string view_source_name; | ||
| std::vector<std::string> columns; | ||
|
|
||
| void bsatn_serialize(::SpacetimeDB::bsatn::Writer& writer) const { | ||
| ::SpacetimeDB::bsatn::serialize(writer, view_source_name); | ||
| ::SpacetimeDB::bsatn::serialize(writer, columns); | ||
| } | ||
| SPACETIMEDB_PRODUCT_TYPE_EQUALITY(view_source_name, columns) | ||
| }; | ||
| } // namespace SpacetimeDB::Internal |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,8 @@ impl Lang for TypeScript { | |
|
|
||
| writeln!(out, "export default __t.row({{"); | ||
| out.indent(1); | ||
| write_object_type_builder_fields(module, out, &product_def.elements, table.primary_key, true, true).unwrap(); | ||
| write_object_type_builder_fields(module, out, "", &product_def.elements, table.primary_key, true, true) | ||
| .unwrap(); | ||
| out.dedent(1); | ||
| writeln!(out, "}});"); | ||
| OutputFile { | ||
|
|
@@ -139,8 +140,16 @@ impl Lang for TypeScript { | |
|
|
||
| writeln!(out, "export const params = {{"); | ||
| out.with_indent(|out| { | ||
| write_object_type_builder_fields(module, out, &procedure.params_for_generate.elements, None, true, false) | ||
| .unwrap() | ||
| write_object_type_builder_fields( | ||
| module, | ||
| out, | ||
| "", | ||
| &procedure.params_for_generate.elements, | ||
| None, | ||
| true, | ||
| false, | ||
| ) | ||
| .unwrap() | ||
| }); | ||
| writeln!(out, "}};"); | ||
|
|
||
|
|
@@ -605,7 +614,7 @@ fn define_body_for_reducer(module: &ModuleDef, out: &mut Indenter, params: &[(Id | |
| writeln!(out, "}};"); | ||
| } else { | ||
| writeln!(out); | ||
| out.with_indent(|out| write_object_type_builder_fields(module, out, params, None, true, false).unwrap()); | ||
| out.with_indent(|out| write_object_type_builder_fields(module, out, "", params, None, true, false).unwrap()); | ||
| writeln!(out, "}};"); | ||
| } | ||
| } | ||
|
|
@@ -630,7 +639,9 @@ fn define_body_for_product( | |
| writeln!(out, "}});"); | ||
| } else { | ||
| writeln!(out); | ||
| out.with_indent(|out| write_object_type_builder_fields(module, out, elements, None, true, false).unwrap()); | ||
| out.with_indent(|out| { | ||
| write_object_type_builder_fields(module, out, name, elements, None, true, false).unwrap() | ||
| }); | ||
| writeln!(out, "}});"); | ||
| } | ||
| writeln!(out, "export type {name} = __Infer<typeof {name}>;"); | ||
|
|
@@ -719,6 +730,7 @@ fn write_table_opts<'a>( | |
| fn write_object_type_builder_fields( | ||
| module: &ModuleDef, | ||
| out: &mut Indenter, | ||
| type_name: &str, | ||
| elements: &[(Identifier, AlgebraicTypeUse)], | ||
| primary_key: Option<ColId>, | ||
| convert_case: bool, | ||
|
|
@@ -736,7 +748,7 @@ fn write_object_type_builder_fields( | |
| None => false, | ||
| }; | ||
| let original_name = (write_original_name && convert_case && *name != **ident).then_some(&**ident); | ||
| write_type_builder_field(module, out, &name, original_name, ty, is_primary_key)?; | ||
| write_type_builder_field(module, out, type_name, &name, original_name, ty, is_primary_key)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
|
|
@@ -755,6 +767,7 @@ fn type_contains_ref(ty: &AlgebraicTypeUse) -> bool { | |
| fn write_type_builder_field( | ||
| module: &ModuleDef, | ||
| out: &mut Indenter, | ||
| type_name: &str, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to option |
||
| name: &str, | ||
| original_name: Option<&str>, | ||
| ty: &AlgebraicTypeUse, | ||
|
|
@@ -764,7 +777,14 @@ fn write_type_builder_field( | |
| let needs_getter = type_contains_ref(ty); | ||
|
|
||
| if needs_getter { | ||
| writeln!(out, "get {name}() {{"); | ||
| if type_name == "RawModuleMountV10" && name == "module" { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to crates/codegen/examples/regen-typescript-moduledef.rs |
||
| // HACK: Fixes a type inference error (TS7022/TS7023) for const types in typescript due to the recursive | ||
| // type: RawModuleDefV10 -> ModuleMountsV10 -> RawModuleDefV10 | ||
| // Annotating this getter with `: any` breaks the cycle without affecting other types. | ||
| writeln!(out, "get {name}(): any {{"); | ||
| } else { | ||
| writeln!(out, "get {name}() {{"); | ||
| } | ||
| out.indent(1); | ||
| write!(out, "return "); | ||
| } else { | ||
|
|
@@ -873,7 +893,9 @@ fn define_body_for_sum( | |
| (Identifier::for_test(pascal), ty.clone()) | ||
| }) | ||
| .collect(); | ||
| out.with_indent(|out| write_object_type_builder_fields(module, out, &pascal_variants, None, false, false).unwrap()); | ||
| out.with_indent(|out| { | ||
| write_object_type_builder_fields(module, out, name, &pascal_variants, None, false, false).unwrap() | ||
| }); | ||
| writeln!(out, "}});"); | ||
| writeln!(out, "export type {name} = __Infer<typeof {name}>;"); | ||
| out.newline(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if this is still necessary