Skip to content

Commit

Permalink
plan
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Jul 1, 2024
1 parent 796e0c0 commit aa255e2
Show file tree
Hide file tree
Showing 333 changed files with 107 additions and 23,927 deletions.
603 changes: 0 additions & 603 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ libc = "0.2.155"
thiserror = "1.0.61"
murmur2 = "0.1.0"
serde_repr = "0.1.19"
rspc = { path = "./external/rspc", features = ["tauri", "axum"] }
tungstenite = { features = ["rustls"], git = "https://github.com/snapview/tungstenite-rs", version = "0.20.1", rev = "fc17f73" }
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "4f9ef9d", features = ["rspc", "specta", "sqlite"] }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "4f9ef9d", features = ["rspc", "specta", "sqlite"] }
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "4f9ef9d", features = ["specta", "sqlite"] }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "4f9ef9d", features = ["specta", "sqlite"] }

wormhole-cli = { path = "./apps/cli" }
wormhole-gui = { path = "./apps/gui" }
Expand All @@ -111,9 +110,6 @@ bindings = { path = "./apps/bindings" }
commands = { path = "./crates/commands" }
plugins = { path = "./crates/plugins" }

[patch."https://github.com/Brendonovich/prisma-client-rust"]
rspc = { path = "./external/rspc" }

[workspace]
resolver = "2"

Expand Down Expand Up @@ -143,5 +139,4 @@ members = [
"crates/plugins",
"crates/pack",
"tools/prisma",
"external/rspc",
]
1 change: 0 additions & 1 deletion apps/gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ log.workspace = true
mcmeta.workspace = true
commands.workspace = true
plugins.workspace = true
rspc.workspace = true

[features]
default = ["custom-protocol"]
Expand Down
1 change: 0 additions & 1 deletion apps/webui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ futures-util.workspace = true
tokio-util.workspace = true
tokio-stream.workspace = true
axumite.workspace = true
rspc.workspace = true
commands.workspace = true
1 change: 0 additions & 1 deletion crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ tracing.workspace = true
install.workspace = true
reqwest.workspace = true
tokio-stream.workspace = true
rspc.workspace = true
1 change: 0 additions & 1 deletion crates/commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ tracing-appender.workspace = true
tracing.workspace = true
log.workspace = true
mcmeta.workspace = true
rspc.workspace = true
midlog.workspace = true
prisma-client-rust.workspace = true
105 changes: 105 additions & 0 deletions crates/rpc-rs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# rpc-rs

A blazingly fast, lightweight, idiomatic, and type-safe RPC/IPC framework for
Rust and Web/Tauri-based applications, based on `specta`.

## Introduction

`rpc-rs` is an idiomatic and type-safe Rust framework for building JSON RPCs and IPCs
for use with Web technologies, such as JavaScript and TypeScript. It follows the basic
CRUD (Create, Read, Update, Delete) pattern, and its syntax allows developers to easily
create complex applications with relatively simple code.

## Syntax

```rust
//! This code may not be completely accurate! I haven't yet built the library and this
//! is all plans! I also don't have ANY intellisense in a markdown file, so I can't check
//! for dumb syntactical errors!

use std::sync::Arc;
use serde::{Serialize, Deserialize};
use specta::Type;
use database::{prisma::{PrismaClient, game}, Game};
use rpc_rs::{Router, Module, ModuleBuilder, PrismaObject};

// The `PrismaObject` derive macro and trait handle the `db_params` function,
// which transforms this struct into a `Vec<SetParam>`. This struct is also
// read from the request body via Serde, hence the `Deserialize` derive macro
// being used here. The `#[prisma(module = ...)]` helper ensures that the derive
// macro finds the correct place to resolve all of the `SetParam` creation
// functions.
#[derive(Debug, Clone, Serialize, Deserialize, Type, PrismaObject)]
#[prisma(module = "database::prisma::game")]
pub struct GameCreation {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub curseforge: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thunderstore: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub spacedock: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ckan: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub modrinth: Option<bool>,
}

pub fn games_module(mut module: ModuleBuilder<State = Arc<PrismaClient>>) -> Module<State = Arc<PrismaClient>> {
module
// This closure is: FnMut(ModuleBuilder::State, GameCreation) -> impl Future<Output = Result<Game, Error>> + Send + Sync + 'static
// The error conversion is handled automatically (via traits)
.create(|db, data: GameCreation| (async move {
// [C]RUD
db.game().create(data.name.clone(), data.db_params()).exec().await
})()) // <- Async closures have to be executed to get the `impl Future<...>`.
// This closure is: FnMut(ModuleBuilder::State, i32) -> impl Future<Output = Result<Game, Error>> + Send + Sync + 'static
.read(|db, id: i32| (async move { // The `id: i32` can be `_: ()` if you don't need any input here.
// C[R]UD
db.game().find_first(vec![game::id::equals(id)]).exec().await
})())
.update(...) // Insert your own functionality here.
.delete(...)
// All the operations get assigned to the `Option<...>` fields in the `ModuleBuilder`
// struct. These will get reassigned to the ones in the `Module` struct and finalized
// when the `build` method is called.
.build()
}

pub fn build_router() -> Router<Arc<PrismaClient>> {
Router::<Arc<PrismaClient>>::new()
.attach(games_module) // Accepts: FnOnce(ModuleBuilder<State = Router::State>) -> Module<State = Router::State>
// This closure is: FnMut(Router::State, ()) -> impl Future<Output = Result<Vec<Game>, Error>> + Send + Sync + 'static
.query("games", |db, _: ()| (async move { // This is useful if you just need a read function.
db.game().find_many(vec![]).exec().await
})())
// The `finish` function finalizes all the state holders and prepares it to be
// mounted with either `axum` or `tauri`.
.finish()
}

#[tokio::main]
pub async fn main() {
let router = build_router();
let db = Arc::new(PrismaClient::_builder().build().await.unwrap());
// Creating the endpoint for axum or the plugin for tauri requires the state object.
let endpoint = router.axum(db);

let router = ...; // Axum stuff.

router.nest("/rpc", endpoint);

// Start your app with axum!
}
```

## Integrations

rpc-rs integrates extremely well with the following libraries and tools:

- `axum`
- `tauri`
- `prisma-client-rust`
- `specta`
- `serde`
- `serde_json`
2 changes: 0 additions & 2 deletions external/rspc/.cargo/config.toml

This file was deleted.

2 changes: 0 additions & 2 deletions external/rspc/.github/FUNDING.yml

This file was deleted.

6 changes: 0 additions & 6 deletions external/rspc/.github/dependabot.yml

This file was deleted.

71 changes: 0 additions & 71 deletions external/rspc/.github/scripts/setPackageVersions.js

This file was deleted.

115 changes: 0 additions & 115 deletions external/rspc/.github/workflows/ci.yml

This file was deleted.

28 changes: 0 additions & 28 deletions external/rspc/.github/workflows/clippy.yml

This file was deleted.

Loading

0 comments on commit aa255e2

Please sign in to comment.