clockworklabs / spacetimedb-csharp-sdk Goto Github PK
View Code? Open in Web Editor NEWThe SpacetimeDB SDK for C# clients
Home Page: https://spacetimedb.com
License: Apache License 2.0
The SpacetimeDB SDK for C# clients
Home Page: https://spacetimedb.com
License: Apache License 2.0
Description:
When attempting to install the spacetimedbsdk package using the .NET CLI in Windows Powershell, I encountered an error indicating that there are no available versions for the package. The documented command to install the package did not work as expected.
Steps to Reproduce:
Expected Result:
The spacetimedbsdk package should be added to the project without any issues.
Actual Result:
Received the following error:
error: There are no versions available for the package 'spacetimedbsdk'.
Additional Information:
.NET CLI Version: Version 7.0.201 (dotnet --info > .NET SDK)
Operating System: Windows 11
Logs:
(base) PS C:\Users\blitz\Desktop\spacetime-test\client> dotnet add package spacetimedbsdk
Determining projects to restore...
Writing C:\Users\blitz\AppData\Local\Temp\tmpE925.tmp
info : X.509 certificate chain validation will use the default trust store selected by .NET.
info : X.509 certificate chain validation will use the default trust store selected by .NET.
info : Adding PackageReference for package 'spacetimedbsdk' into project 'C:\Users\blitz\Desktop\spacetime-test\client\client.csproj'.
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/spacetimedbsdk/index.json
info : CACHE https://api.nuget.org/v3/registration5-gz-semver2/spacetimedbsdk/index.json
error: There are no versions available for the package 'spacetimedbsdk'.
Incremental Generators could be used to automatically generate and update C# entities and reducers. A first time user experience for the SpacetimeDB C# SDK could be as simple as:
SpacetimeDB.ClientSDK
nuget packageHere is a proof of concept for the current (as of February 2024) SDK which could be an alternative to the FindReducerType
approach:
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;
namespace SpacetimeDBAutogen;
[Generator]
public class ReducerCacheGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext initContext)
{
IncrementalValuesProvider<(string FunctionName, string MethodName)> reducerProvider = initContext.SyntaxProvider
.ForAttributeWithMetadataName(
"SpacetimeDB.ReducerCallbackAttribute",
predicate: (_, _) => true,
transform: static (ctx, _) => {
var functionNameAttribute = ctx.Attributes
.Where(a=>a.AttributeClass.ToDisplayString() == "SpacetimeDB.ReducerCallbackAttribute")
.SelectMany(a => a.NamedArguments)
.Where(na => na.Key == "FunctionName")
.Select(na => na.Value)
.FirstOrDefault();
var displayString = ctx.TargetSymbol.ToDisplayString();
displayString = displayString.Substring(0, displayString.IndexOf('('));
return (functionNameAttribute.Value.ToString(), displayString);
});
IncrementalValueProvider<ImmutableArray<(string FunctionName, string MethodName)>> collected = reducerProvider.Collect();
initContext.RegisterSourceOutput(collected, static (sourceProductionContext, reducers) =>
{
sourceProductionContext.AddSource("ReducerCache.g.cs", $$"""
namespace SpacetimeDB;
public static class SpacetimeDBClientReducers
{
static SpacetimeDBClientReducers()
{{{reducers
.Aggregate("", (c, n) => c + "\n SpacetimeDBClient.reducerEventCache.Add(\"" + n.FunctionName + "\", " + n.MethodName + ");")
}}
}
}
""");
});
}
}
Which outputs:
namespace SpacetimeDB;
public static class SpacetimeDBClientReducers
{
static SpacetimeDBClientReducers()
{
SpacetimeDBClient.reducerEventCache.Add("set_name", SpacetimeDB.Types.Reducer.OnSetName);
SpacetimeDBClient.reducerEventCache.Add("send_message", SpacetimeDB.Types.Reducer.OnSendMessage);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.