SpacetimeDB.Codegen 0.8.1

dotnet add package SpacetimeDB.Codegen --version 0.8.1
NuGet\Install-Package SpacetimeDB.Codegen -Version 0.8.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpacetimeDB.Codegen" Version="0.8.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpacetimeDB.Codegen --version 0.8.1
#r "nuget: SpacetimeDB.Codegen, 0.8.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SpacetimeDB.Codegen as a Cake Addin
#addin nuget:?package=SpacetimeDB.Codegen&version=0.8.1

// Install SpacetimeDB.Codegen as a Cake Tool
#tool nuget:?package=SpacetimeDB.Codegen&version=0.8.1

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 a GetSatsTypeInfo() static method that registers this type with the runtime and returns a TypeInfo object. It supports only structs 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 static TypeInfo properties and helper methods on SpacetimeDB.SATS.BuiltinType (Runtime/AlgebraicType.cs) and routing logic in Utils.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 interface SpacetimeDB.TaggedEnum<Variants> where Variants is a named tuple of all possible variants, e.g.:

    [SpacetimeDB.Type]
    partial struct Option<T> : SpacetimeDB.TaggedEnum<(T Some, Unit None)> { }
    

    will generate properties bool IsSome, bool IsNone, T Some, and Unit None for the Option<T> type.

    The Some and None accessors will throw an exception if the type is not in the corresponding state, so you must use Is* checks if you don't know which variant is currently active.

    All of those properties are stored in a compact byte + object pair representation.

  • [SpacetimeDB.Table] - generates code to register this table in the FFI 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 the FFI 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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SpacetimeDB.Codegen:

Package Downloads
SpacetimeDB.Runtime

The SpacetimeDB Runtime implements the database runtime bindings for writing SpacetimeDB modules in C#.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.1 334 12/7/2023
0.8.1-naot-experimental 65 1/10/2024
0.8.0 83 11/30/2023
0.7.3 178 10/26/2023
0.7.2 153 10/11/2023
0.7.1 118 10/3/2023
0.7.0 273 9/12/2023
0.6.2 195 8/14/2023
0.6.1 185 8/8/2023
0.6.0 272 8/2/2023