Giter Site home page Giter Site logo

spacetimedb-csharp-sdk's People

Contributors

aasoni avatar cloutiertyler avatar dbrinkmann-citadel avatar dbrinkmanncw avatar jdetter avatar steveboytsun avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacetimedb-csharp-sdk's Issues

Unable to Install spacetimedbsdk Package Using .NET CLI in Windows Powershell

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:

  1. Open Windows Powershell.
  2. Navigate to the project directory: (In my case: C:\Users\blitz\Desktop\spacetime-test\client)
  3. Run the command: dotnet add package spacetimedbsdk

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'.

Consider Incremental Generators for a better user experience

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:

  1. Create new project
  2. Add reference to SpacetimeDB.ClientSDK nuget package
  3. Configure database connectivity
  4. Source generator runs and creates entities and reducers

Here 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);
    }
}

Refactor SDK BSATN implementation

  • Reuse as much code from the C# module SDK where possible
  • Get rid of most reflection if we can
  • This requires updating the C# autogen reducer functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.