SpacetimeDB.Codegen
0.10.0
dotnet add package SpacetimeDB.Codegen --version 0.10.0
NuGet\Install-Package SpacetimeDB.Codegen -Version 0.10.0
<PackageReference Include="SpacetimeDB.Codegen" Version="0.10.0" />
paket add SpacetimeDB.Codegen --version 0.10.0
#r "nuget: SpacetimeDB.Codegen, 0.10.0"
// Install SpacetimeDB.Codegen as a Cake Addin
#addin nuget:?package=SpacetimeDB.Codegen&version=0.10.0
// Install SpacetimeDB.Codegen as a Cake Tool
#tool nuget:?package=SpacetimeDB.Codegen&version=0.10.0
SpacetimeDB.Codegen
This project contains Roslyn incremental source generators that augment types and tables with static methods for self-describing and registration. They look for different attributes to know which types to augment:
[SpacetimeDB.Type]
- generates aGetSatsTypeInfo()
static method that registers this type with the runtime and returns aTypeInfo
object. It supports onlystruct
s for now to explicitly forbid infinitely recursive types and to make the implementation simpler, as it doesn't need to deal with type references - each table is registered as an entirely self-contained type together with its nested structs if any. This is unlikely to be a problem in common scenarios, but it will be optimised in the future.All the nested fields will be added to the product type. Because it's not possible to implement static extension methods on 3rd-party types (including built-ins) in C#, the codegen is responsible for manually routing different types to their
TypeInfo
descriptors. See various staticTypeInfo
properties and helper methods onSpacetimeDB.BSATN.BuiltinType
(Runtime/AlgebraicType.cs
) and routing logic inUtils.GetTypeInfo
(Codegen/Utils.cs
) for more details.Also, for the same reason - absence of static extension methods in C# - the codegen expects that your struct, as well as any of its parents, is
partial
so methods can be added from extra source files generated by the codegen.[SpacetimeDB.Type]
- also supports emulation of tagged enums in C#. For that, the struct needs to inherit a marker interfaceSpacetimeDB.TaggedEnum<Variants>
whereVariants
is a named tuple of all possible variants, e.g.:[SpacetimeDB.Type] partial record Option<T> : SpacetimeDB.TaggedEnum<(T Some, Unit None)>;
will generate inherited records
Option.Some(T Some_)
andOption.None(Unit None_)
. It allows you to use tagged enums in C# in a similar way to Rust enums by leveraging C# pattern-matching on any instance ofOption<T>
.[SpacetimeDB.Table]
- generates code to register this table in theFFI
upon startup so that they can be enumerated by the__describe_module__
FFI API. It implies[SpacetimeDB.Type]
, so you must not specify both attributes on the same struct.The fields can be marked with
[SpacetimeDB.ColumnAttrs]
and those will be detected by the codegen and passed on to the runtime as well. Example:[SpacetimeDB.Table] public partial struct Person { [SpacetimeDB.Column(ColumnAttrs.Identity)] public int Id; public string Name; }
[SpacetimeDB.Reducer]
- generates code to register a static function as a SpacetimeDB reducer in theFFI
upon startup and creates a wrapper that will parse SATS binary blob into individual arguments and invoke the underlying function for the__call_reducer__
FFI API.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.10.0 | 34 | 6/13/2024 |
0.9.2 | 91 | 5/28/2024 |
0.9.0 | 82 | 5/22/2024 |
0.8.1 | 347 | 12/7/2023 |
0.8.1-naot-experimental | 66 | 1/10/2024 |
0.8.0 | 92 | 11/30/2023 |
0.7.3 | 180 | 10/26/2023 |
0.7.2 | 153 | 10/11/2023 |
0.7.1 | 118 | 10/3/2023 |
0.7.0 | 274 | 9/12/2023 |
0.6.2 | 196 | 8/14/2023 |
0.6.1 | 185 | 8/8/2023 |
0.6.0 | 278 | 8/2/2023 |