chore: Remove prisma and fix up some actions

This commit is contained in:
LynithDev 2024-10-18 19:52:17 +02:00
parent f6c997e292
commit 15172d5537
24 changed files with 92 additions and 2733 deletions

View file

@ -32,6 +32,3 @@ linker = "clang"
rustflags = ["-C", "link-args=-fuse-ld={{{linker}}}"]
{{/hasLLD}}
{{/isLinux}}
[alias]
prisma = "run -p onelauncher_prisma_cli --bin prisma --"

View file

@ -40,47 +40,3 @@ runs:
- name: Prepare Cargo
shell: bash
run: echo '{}' | npx -y mustache - .cargo/config.toml.mustache .cargo/config.toml
- name: Prisma Cache
id: prisma-cache
uses: actions/cache/restore@v4
with:
key: prisma-v1-${{ runner.os }}-${{ hashFiles('./packages/core/prisma/*', './Cargo.*') }}
path: packages/prisma/src/**/*.rs
- name: Generate Prisma
if: ${{ steps.prisma-cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
set -euxo pipefail
npx -y prisma generate --schema packages/core/prisma/schema.prisma
if ! [ -f packages/prisma/src/prisma/mod.rs ]; then
echo "prisma generation failed" >&2
exit 1
fi
npx -y prisma migrate dev --schema packages/core/prisma/schema.prisma -n test --create-only --skip-generate
_new_migrations="$(
git ls-files --others --exclude-standard \
| { grep '^prisma/migrations/' || true; } \
| xargs sh -euxc '[ "$#" -lt 2 ] || grep -L "$@" || true' sh 'empty migration' \
| wc -l \
| awk '{$1=$1};1'
)"
if [ "$_new_migrations" -gt 0 ]; then
echo "::error file=packages/core/prisma/schema.prisma,title=missing migration::new migration should be generated due to changes in prisma schema"
case "$GITHUB_REF" in
"refs/heads/main" | "refs/heads/gh-readonly-queue/main/"* | "refs/tags/"*)
exit 1
;;
esac
fi
- name: Save Prisma Cache
id: prisma-cache-save
if: ${{ steps.prisma-cache.outputs.cache-hit != 'true' && (github.ref == 'refs/heads/main' || inputs.save-cache == 'true') }}
uses: actions/cache/save@v4
with:
key: ${{ steps.cache-prisma-restore.outputs.cache-primary-key }}
path: packages/prisma/src/**/*.rs

View file

@ -23,9 +23,7 @@ jobs:
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1))" >> "${GITHUB_ENV}"
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
uses: actions/checkout@4
- name: Setup Pnpm
uses: ./.github/actions/setup-pnpm
@ -38,6 +36,10 @@ jobs:
name: Rust Checks
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install system packages
- name: Checkout
uses: actions/checkout@v4
- name: Run Clippy
run: cargo clippy --all-targets --all-features

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
crates/prisma/src/prisma.rs
dev.db
dev.db-journal
.cargo/config.toml

View file

@ -6,7 +6,6 @@
"oscarbeaumont.rspc-vscode", // RSPC is a framework for Routers.
"antfu.unocss", // Provides UnoCSS intellisense.
"EditorConfig.EditorConfig", // Maintains consistent coding styles.
"prisma.prisma", // Prisma is an open-source ORM database toolkit.
"dbaeumer.vscode-eslint" // Code formatting using ESLint.
]
}

2026
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,8 +6,6 @@ members = [
"packages/core", # onelauncher -- the rust core for onelauncher
"packages/macros", # onelauncher_macros -- utility procedural macros for onelauncher
"packages/gamemode", # onelauncher_gamemode -- rust wrapper for feral gamemode
"packages/prisma-cli", # onelauncher_prisma_cli -- rust wrapper for prisma cli
"packages/prisma", # onelauncher_prisma -- rust client for prisma
"packages/utils" # onelauncher_utils -- standard utilities for use within all crates
]
@ -30,8 +28,6 @@ onelauncher_macros = { path = "./packages/macros" }
onelauncher_gui = { path = "./apps/desktop" }
onelauncher_test = { path = "./apps/testing" }
onelauncher_gamemode = { path = "./packages/gamemode" }
onelauncher_prisma = { path = "./packages/prisma" }
onelauncher_prisma_cli = { path = "./packages/prisma-cli" }
onelauncher_utils = { path = "./packages/utils" }
# # ============= TAURI ============= # #
@ -165,30 +161,6 @@ dotenvy = { git = "https://github.com/allan2/dotenvy/", rev = "db0d6aa8fc8d1b0dd
# https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/Cargo.toml#L102
webkit2gtk = { version = "=2.0.1", features = [ "v2_40" ] }
[workspace.dependencies.prisma-client-rust]
git = "https://github.com/brendonovich/prisma-client-rust"
rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab"
features = [
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
"rspc"
]
default-features = false
[workspace.dependencies.prisma-client-rust-generator]
git = "https://github.com/brendonovich/prisma-client-rust"
rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab"
features = [
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
"rspc"
]
default-features = false
[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }

View file

@ -24,7 +24,6 @@
"scripts": {
"prep": "pnpm scripts prep",
"typecheck": "pnpm -r typecheck",
"codegen": "pnpm prisma:gen",
"bootstrap": "cargo clean && ./packages/scripts/setup.sh && pnpm install && pnpm prep && pnpm codegen",
"autoformat": "./packages/scripts/format.sh",
"test": "pnpm test:vi && pnpm --filter=./* run test",
@ -45,9 +44,7 @@
"lint:es": "eslint . --cache --flag unstable_ts_config",
"format:es": "pnpm lint:es --fix",
"lint:rs": "cargo +nightly fmt --check && cargo clippy -- -D warnings",
"format:rs": "cargo +nightly fmt && cargo clippy --fix",
"prisma:gen": "pnpm prisma generate --schema packages/core/prisma/schema.prisma",
"prisma:migrate": "pnpm prisma migrate dev --schema packages/core/prisma/schema.prisma"
"format:rs": "cargo +nightly fmt && cargo clippy --fix"
},
"workspaces": {
"packages": [
@ -63,7 +60,6 @@
"eslint": "^9.11.1",
"eslint-plugin-solid": "^0.14.3",
"jiti": "^2.0.0",
"prisma": "^5.20.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"tsx": "^4.19.1",

View file

@ -24,7 +24,6 @@ workspace = true
[dependencies]
# features[default]
onelauncher_macros = { workspace = true }
onelauncher_prisma = { workspace = true }
onelauncher_utils = { workspace = true }
interpulse = { workspace = true }
tracing = { workspace = true }

View file

@ -1,210 +0,0 @@
-- CreateTable
CREATE TABLE "settings" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0,
"theme" TEXT NOT NULL DEFAULT 'dark',
"hide_close_prompt" BOOLEAN NOT NULL DEFAULT true,
"reduced_motion" BOOLEAN NOT NULL DEFAULT false,
"disable_analytics" BOOLEAN NOT NULL DEFAULT false,
"debug_mode" BOOLEAN NOT NULL DEFAULT false,
"hide_on_launch" BOOLEAN NOT NULL DEFAULT false,
"force_fullscreen" BOOLEAN NOT NULL DEFAULT false,
"disable_discord" BOOLEAN NOT NULL DEFAULT false,
"release_channel" TEXT NOT NULL DEFAULT 'stable',
"show_news" BOOLEAN NOT NULL DEFAULT true,
"advanced_rendering" BOOLEAN NOT NULL DEFAULT true,
"allow_parallel" BOOLEAN NOT NULL DEFAULT true,
"enable_gamemode" BOOLEAN NOT NULL DEFAULT true,
"custom_java_args" TEXT NOT NULL,
"custom_env_args" TEXT NOT NULL,
"max_async_io_operations" INTEGER NOT NULL DEFAULT 10,
"max_async_fetches" INTEGER NOT NULL DEFAULT 10,
"max_async_api_fetches" INTEGER NOT NULL DEFAULT 25,
"resolution_x" INTEGER NOT NULL DEFAULT 854,
"resolution_y" INTEGER NOT NULL DEFAULT 480,
"memory_max" INTEGER NOT NULL DEFAULT 2048,
"memory_min" INTEGER NOT NULL DEFAULT 256,
"hook_pre" TEXT,
"hook_wrapper" TEXT,
"hook_post" TEXT
);
-- CreateTable
CREATE TABLE "java_version" (
"id" TEXT NOT NULL PRIMARY KEY,
"major_version" INTEGER NOT NULL,
"full_version" TEXT NOT NULL,
"arch" TEXT NOT NULL,
"os" TEXT NOT NULL,
"type" TEXT NOT NULL,
"vendor" TEXT NOT NULL,
"path" TEXT NOT NULL,
"valid" BOOLEAN NOT NULL DEFAULT true
);
-- CreateTable
CREATE TABLE "java_profile" (
"name" TEXT NOT NULL PRIMARY KEY,
"system" BOOLEAN NOT NULL DEFAULT false,
"java_id" TEXT,
CONSTRAINT "java_profile_java_id_fkey" FOREIGN KEY ("java_id") REFERENCES "java_version" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "minecraft_user" (
"uuid" TEXT NOT NULL PRIMARY KEY,
"active" BOOLEAN NOT NULL DEFAULT false,
"username" TEXT NOT NULL,
"access_token" TEXT NOT NULL,
"refresh_token" TEXT NOT NULL,
"expires" DATETIME NOT NULL,
"last_used" DATETIME NOT NULL,
"skin_id" TEXT
);
-- CreateTable
CREATE TABLE "skin" (
"id" TEXT NOT NULL PRIMARY KEY,
"skin" BLOB NOT NULL
);
-- CreateTable
CREATE TABLE "minecraft_device_token" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0,
"uuid" TEXT NOT NULL,
"private_key" TEXT NOT NULL,
"x" TEXT NOT NULL,
"y" TEXT NOT NULL,
"issue_instant" INTEGER NOT NULL,
"not_after" INTEGER NOT NULL,
"token" TEXT NOT NULL,
"display_claims" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "cluster" (
"path" TEXT NOT NULL PRIMARY KEY,
"stage" TEXT NOT NULL,
"name" TEXT NOT NULL,
"icon_path" TEXT,
"mc_version" TEXT NOT NULL,
"loader" TEXT NOT NULL DEFAULT 'vanilla',
"loader_version" TEXT DEFAULT 'stable',
"group_id" INTEGER NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" DATETIME NOT NULL,
"played_at" DATETIME,
"overall_played" INTEGER NOT NULL DEFAULT 0,
"recently_played" INTEGER NOT NULL DEFAULT 0,
"override_java_path" TEXT,
"override_custom_java_args" TEXT NOT NULL,
"override_custom_env_args" TEXT NOT NULL,
"override_memory_max" INTEGER,
"override_memory_min" INTEGER,
"override_force_fullscreen" INTEGER,
"override_resolution_x" INTEGER,
"override_resolution_y" INTEGER,
"override_hook_pre" TEXT,
"override_hook_wrapper" TEXT,
"override_hook_post" TEXT,
CONSTRAINT "cluster_group_id_fkey" FOREIGN KEY ("group_id") REFERENCES "cluster_group" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "cluster_group" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"index" INTEGER NOT NULL
);
-- CreateTable
CREATE TABLE "process" (
"pid" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"start_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" TEXT NOT NULL,
"executable" TEXT NOT NULL,
"cluster_path" TEXT NOT NULL,
"post_exit" TEXT,
CONSTRAINT "process_cluster_path_fkey" FOREIGN KEY ("cluster_path") REFERENCES "cluster" ("path") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "version_info_cache" (
"id" TEXT NOT NULL PRIMARY KEY,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"version_info" BLOB NOT NULL
);
-- CreateTable
CREATE TABLE "partial_version_info" (
"id" TEXT NOT NULL PRIMARY KEY,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"version_info" BLOB NOT NULL
);
-- CreateTable
CREATE TABLE "assets_index_cache" (
"id" TEXT NOT NULL PRIMARY KEY,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"assets_index" BLOB NOT NULL
);
-- CreateTable
CREATE TABLE "package_cache" (
"id" TEXT NOT NULL PRIMARY KEY,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"sha512" TEXT NOT NULL,
"file_name" TEXT NOT NULL,
"file_size" INTEGER NOT NULL,
"disabled" BOOLEAN NOT NULL,
"meta_id" TEXT NOT NULL,
CONSTRAINT "package_cache_meta_id_fkey" FOREIGN KEY ("meta_id") REFERENCES "package_metadata" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "package_metadata" (
"id" TEXT NOT NULL PRIMARY KEY,
"updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" TEXT,
"package_id" TEXT,
"version" TEXT,
"description" TEXT,
"authors" TEXT,
"loader" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "managed_mod_cache" (
"meta_id" TEXT NOT NULL PRIMARY KEY,
"project_id" INTEGER NOT NULL,
"file_id" INTEGER NOT NULL,
"name" TEXT NOT NULL,
"version" TEXT NOT NULL,
"urlslug" TEXT NOT NULL,
"summary" TEXT NOT NULL,
"authors" TEXT NOT NULL,
"release_type" INTEGER NOT NULL,
"update_paths" TEXT NOT NULL,
"cached_at" DATETIME NOT NULL,
CONSTRAINT "managed_mod_cache_meta_id_fkey" FOREIGN KEY ("meta_id") REFERENCES "package_metadata" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "settings_id_key" ON "settings"("id");
-- CreateIndex
CREATE UNIQUE INDEX "java_version_id_key" ON "java_version"("id");
-- CreateIndex
CREATE UNIQUE INDEX "java_version_path_key" ON "java_version"("path");
-- CreateIndex
CREATE UNIQUE INDEX "minecraft_user_active_key" ON "minecraft_user"("active");
-- CreateIndex
CREATE INDEX "process_cluster_path_idx" ON "process"("cluster_path");
-- CreateIndex
CREATE UNIQUE INDEX "process_pid_key" ON "process"("pid");
-- CreateIndex
CREATE UNIQUE INDEX "package_cache_file_name_key" ON "package_cache"("file_name");

View file

@ -1,3 +0,0 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"

View file

@ -1,272 +0,0 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
}
generator client {
provider = "cargo prisma"
output = "../../prisma/src/prisma"
module_path = "prisma"
client_format = "folder"
}
/// A global settings state for the launcher.
model Settings {
/// The unique ID associated with this Settings instance.
id Int @id @unique @default(0)
/// A OneLauncher theme managed by the core GUI. (system, light, dark, oled, mocha)
theme String @default("dark")
/// Whether or not ask for confirmation when closing the core GUI.
hide_close_prompt Boolean @default(true)
/// Disables animations in the core GUI.
reduced_motion Boolean @default(false)
/// Whether or not to disable Plausible and Sentry analytics.
disable_analytics Boolean @default(false)
/// Whether or not to enable a debug mode in the launcher.
debug_mode Boolean @default(false)
/// Whether or not to minimize the launcher upon a game launch.
hide_on_launch Boolean @default(false)
/// A global fullscreen Minecraft state.
force_fullscreen Boolean @default(false)
/// Whether or not to disable Discord IPC.
disable_discord Boolean @default(false)
/// The release channel of the launcher. ("stable","beta","alpha").
release_channel String @default("stable")
/// Whether or not to show news and release notes in the launcher.
show_news Boolean @default(true)
/// Enable/disable advanced rendering and window decorations.
advanced_rendering Boolean @default(true)
/// Whether to allow launching the same cluster under the same account.
allow_parallel Boolean @default(true)
/// Whether to launch Feral Gamemode on Linux systems.
enable_gamemode Boolean @default(true)
/// Global and default custom Java arguments. This is parsed as a `Vec<String>` in Rust.
custom_java_args String
/// Global and default custom environment variables. This is parsed as a `Vec<String>` in Rust.
custom_env_args String
/// Global and default maximum `Semaphore` I/O operations.
max_async_io_operations Int @default(10)
/// Global and default maximum `Semaphore` HTTP operations.
max_async_fetches Int @default(10)
/// Global and default maximum `Semaphore` API HTTP operations.
max_async_api_fetches Int @default(25)
/// Global and default Minecraft window resoluton on the X axis.
resolution_x Int @default(854)
/// Global and default Minecraft window resoluton on the Y axis.
resolution_y Int @default(480)
/// Maximum amount of Java memory available globally.
memory_max Int @default(2048)
/// Minimum amount of Java memory available globally.
memory_min Int @default(256)
/// Global and default preinitialization hook.
hook_pre String?
/// Global and default wrapper hook.
hook_wrapper String?
/// Global and default postinitialization hook.
hook_post String?
@@map("settings")
}
/// A structure representing a single version of the Java Runtime Environment.
model JavaVersion {
/// The unique UUID associated with this Java version.
id String @id @unique @default(uuid())
/// The major Java version of this Java version (8, 16, 21).
major_version Int
/// The full Java version of this Java version.
full_version String
/// The architecture that this Java version was built for.
arch String
/// The OS that this Java version was built for.
os String
/// The type of Java installation that this Java version is.
type String
/// The vendor of this Java version (Adoptium, OpenJDK, Oracle).
vendor String
/// The unique path location of this Java version.
path String @unique
/// Whether or not this Java version is valid.
valid Boolean @default(true)
profile JavaProfile[]
@@map("java_version")
}
model JavaProfile {
name String @id
system Boolean @default(false)
java_version JavaVersion? @relation(fields: [java_id], references: [id], onDelete: SetNull)
java_id String?
@@map("java_profile")
}
model MinecraftUser {
uuid String @id
active Boolean @default(false)
username String
access_token String
refresh_token String
expires DateTime
last_used DateTime
skin_id String?
@@unique([active])
@@map("minecraft_user")
}
model Skin {
id String @id
skin Bytes
@@map("skin")
}
// TODO: packages/caching
model MinecraftDeviceToken {
id Int @id @default(0)
uuid String
private_key String
x String
y String
issue_instant Int
not_after Int
token String
display_claims String
@@map("minecraft_device_token")
}
model Cluster {
path String @id
stage String
name String
icon_path String?
mc_version String
loader String @default("vanilla")
loader_version String? @default("stable")
group ClusterGroup @relation(fields: [group_id], references: [id])
group_id Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt
played_at DateTime?
overall_played Int @default(0)
recently_played Int @default(0)
override_java_path String?
override_custom_java_args String
override_custom_env_args String
override_memory_max Int?
override_memory_min Int?
override_force_fullscreen Int?
override_resolution_x Int?
override_resolution_y Int?
override_hook_pre String?
override_hook_wrapper String?
override_hook_post String?
processes Process[]
@@map("cluster")
}
model ClusterGroup {
id Int @id @default(autoincrement())
name String
index Int
clusters Cluster[]
@@map("cluster_group")
}
model Process {
pid Int @id
start_time DateTime @default(now())
name String
executable String
cluster_path String
post_exit String?
cluster Cluster @relation(fields: [cluster_path], references: [path])
@@unique([pid])
@@index([cluster_path])
@@map("process")
}
model VersionInfoCache {
id String @id
updated_at DateTime @default(now()) @updatedAt
version_info Bytes
@@map("version_info_cache")
}
model PartialVersionInfoCache {
id String @id
updated_at DateTime @default(now()) @updatedAt
version_info Bytes
@@map("partial_version_info")
}
model AssetsIndexCache {
id String @id
updated_at DateTime @default(now()) @updatedAt
assets_index Bytes
@@map("assets_index_cache")
}
model PackageCache {
id String @id @default(uuid())
updated_at DateTime @default(now()) @updatedAt
sha512 String
file_name String
file_size Int
disabled Boolean
meta_id String
meta PackageMetadata @relation(fields: [meta_id], references: [id], onDelete: Restrict)
@@unique([file_name])
@@map("package_cache")
}
model PackageMetadata {
id String @id
updated_at DateTime @default(now()) @updatedAt
name String?
package_id String?
version String?
description String?
authors String?
loader String
// icon IconCache?
managed ManagedModCache?
// inferred InferredModCache?
cached PackageCache[]
@@map("package_metadata")
}
model ManagedModCache {
meta_id String @id
project_id Int
file_id Int
name String
version String
urlslug String
summary String
authors String
release_type Int
update_paths String
cached_at DateTime
meta PackageMetadata @relation(fields: [meta_id], references: [id], onDelete: Cascade)
@@map("managed_mod_cache")
}

View file

@ -4,7 +4,7 @@ use crate::State;
pub use interpulse::api::minecraft::VersionManifest;
pub use interpulse::api::modded::Manifest;
// TODO: better error handling (prisma?)
// TODO: better error handling
// TODO: fix this lmao
/// Get a [`VersionManifest`] for all available Minecraft versions.

View file

@ -182,7 +182,7 @@ impl From<InnerPathLinux> for RawPackagePath {
}
}
// TODO: make it not a pathbuf, just get rid of all packagepath and clusterpath into str. maybe even just go straight to prisma with strings
// TODO: make it not a pathbuf, just get rid of all packagepath and clusterpath into str.
/// Relative [`PathBuf`] for a specific [`Package`] of a [`Cluster`].
#[cfg_attr(feature = "specta", derive(specta::Type))]

View file

@ -1,14 +0,0 @@
[package]
name = "onelauncher_prisma_cli"
description = "prisma cli wrapper for onelauncher"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }
[dependencies]
prisma-client-rust-generator = { workspace = true }

View file

@ -1,14 +0,0 @@
{
"name": "@onelauncher/prisma-cli",
"version": "1.0.0-alpha.1",
"description": "Next-generation open source Minecraft launcher primsa cli bindings",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
"url": "git@github.com:polyfrost/onelauncher",
"directory": "packages/prisma-cli"
},
"bugs": "https://github.com/polyfrost/onelauncher/issues",
"sideEffects": false,
"scripts": {}
}

View file

@ -1,3 +0,0 @@
fn main() {
prisma_client_rust_generator::run();
}

View file

@ -1 +0,0 @@
src/*/

View file

@ -1,16 +0,0 @@
[package]
name = "onelauncher_prisma"
description = "prisma client for onelauncher"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }
[dependencies]
prisma-client-rust = { workspace = true }
serde = { workspace = true }
uuid = { workspace = true }

View file

@ -1,14 +0,0 @@
{
"name": "@onelauncher/prisma",
"version": "1.0.0-alpha.1",
"description": "Next-generation open source Minecraft launcher prisma bindings",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
"url": "git@github.com:polyfrost/onelauncher",
"directory": "packages/prisma"
},
"bugs": "https://github.com/polyfrost/onelauncher/issues",
"sideEffects": false,
"scripts": {}
}

View file

@ -1,15 +0,0 @@
#![recursion_limit = "256"]
#[allow(warnings, unused)]
#[rustfmt::skip]
pub mod prisma;
pub async fn test_db() -> std::sync::Arc<prisma::PrismaClient> {
std::sync::Arc::new(
prisma::PrismaClient::_builder()
.with_url(format!("file:/tmp/test-db-{}", uuid::Uuid::new_v4()))
.build()
.await
.unwrap(),
)
}

View file

@ -14,7 +14,6 @@ authors = { workspace = true }
workspace = true
[dependencies]
onelauncher_prisma = { workspace = true }
serde = { workspace = true }
uuid = { workspace = true }
async-channel = { workspace = true }
@ -30,6 +29,5 @@ chrono = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
nom = { workspace = true }
prisma-client-rust = { workspace = true }
regex = { workspace = true }
interpulse = { workspace = true }

View file

@ -8,7 +8,6 @@
pub mod io;
pub mod logging;
pub mod platform;
pub mod prisma;
/// Simple macro that takes a mutable reference and inserts it into a codeblock closure
/// as an owned reference.

View file

@ -1,136 +0,0 @@
use onelauncher_prisma::prisma::PrismaClient;
use prisma_client_rust::migrations::{DbPushError, MigrateDeployError};
use prisma_client_rust::NewClientError;
/// Represents an error that occured while opening and running migrations
/// on the [`prisma_client_rust`] database.
#[derive(thiserror::Error, Debug)]
pub enum MigrationError {
#[error("failed to initialize a new database connection: {0}")]
NewClient(#[from] Box<NewClientError>),
#[error("failed to migrate the database: {0}")]
MigrateFailed(#[from] MigrateDeployError),
#[cfg(debug_assertions)]
#[error("failed to migrate the database: {0}")]
DbPushFailed(#[from] DbPushError),
}
/// Loads the database from the given path and migrates it to the latest schema.
pub async fn load_and_migrate(db_url: &str) -> Result<PrismaClient, MigrationError> {
let client = PrismaClient::_builder()
.with_url(db_url.to_string())
.build()
.await
.map_err(Box::new)?;
client._migrate_deploy().await?;
#[cfg(debug_assertions)]
{
let mut builder = client._db_push();
if std::env::var("ONELAUNCHER_DO_NOT_USE_THIS")
.map(|v| v == "true")
.unwrap_or(false)
{
builder = builder.accept_data_loss();
}
if std::env::var("ONELAUNCHER_FORCE_RESET")
.map(|v| v == "true")
.unwrap_or(false)
{
builder = builder.force_reset();
}
let res = builder.await;
match res {
Ok(_) => {}
Err(e @ DbPushError::PossibleDataLoss(_)) => {
eprintln!("pushing prisma schema may result in data loss. use `ONELAUNCHER_DO_NOT_USE_THIS=true` to force it.");
Err(e)?;
}
Err(e) => Err(e)?,
}
}
Ok(client)
}
/// Construct back an inode after storing it in database
#[must_use]
pub const fn inode_from_db(db_inode: &[u8]) -> u64 {
u64::from_le_bytes([
db_inode[0],
db_inode[1],
db_inode[2],
db_inode[3],
db_inode[4],
db_inode[5],
db_inode[6],
db_inode[7],
])
}
#[must_use]
pub fn inode_to_db(inode: u64) -> Vec<u8> {
inode.to_le_bytes().to_vec()
}
#[must_use]
pub const fn size_in_bytes_from_db(db_size_in_bytes: &[u8]) -> u64 {
u64::from_be_bytes([
db_size_in_bytes[0],
db_size_in_bytes[1],
db_size_in_bytes[2],
db_size_in_bytes[3],
db_size_in_bytes[4],
db_size_in_bytes[5],
db_size_in_bytes[6],
db_size_in_bytes[7],
])
}
#[must_use]
pub fn size_in_bytes_to_db(size: u64) -> Vec<u8> {
size.to_be_bytes().to_vec()
}
#[derive(thiserror::Error, Debug)]
#[error("missing database field {0}")]
pub struct MissingFieldError(&'static str);
impl MissingFieldError {
#[must_use]
pub const fn new(value: &'static str) -> Self {
Self(value)
}
}
pub trait OptionalField: Sized {
type Out;
fn transform(self) -> Option<Self::Out>;
}
impl<T> OptionalField for Option<T> {
type Out = T;
fn transform(self) -> Self {
self
}
}
impl<'a, T> OptionalField for &'a Option<T> {
type Out = &'a T;
fn transform(self) -> Option<Self::Out> {
self.as_ref()
}
}
pub fn maybe_missing<T: OptionalField>(
data: T,
field: &'static str,
) -> Result<T::Out, MissingFieldError> {
data.transform().ok_or(MissingFieldError(field))
}