Skip to content

Commit

Permalink
fix: fix ts generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Dec 6, 2024
1 parent f70947c commit 4707547
Show file tree
Hide file tree
Showing 144 changed files with 1,075 additions and 537 deletions.
2 changes: 1 addition & 1 deletion packages/common/config/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use global_error::prelude::*;
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub mod server;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/config/src/config/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;

use global_error::prelude::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;
use schemars::JsonSchema;

use crate::secret::Secret;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::net::Ipv4Addr;

use ipnet::{Ipv4AddrRange, Ipv4Net};
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
Expand Down
2 changes: 1 addition & 1 deletion packages/common/config/src/config/server/rivet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use global_error::prelude::*;
use maplit::hashmap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, net::IpAddr, path::PathBuf};
use url::Url;
use schemars::JsonSchema;
use uuid::Uuid;

use crate::secret::Secret;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/config/src/secret.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
use schemars::JsonSchema;

/// Wraps a given value in a container that does not implement `Debug` or `Display` in order to
/// prevent accidentally logging the inner secret.
Expand Down
4 changes: 2 additions & 2 deletions packages/common/convert/src/convert/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn summary(
config: &rivet_config::Config,
game: &backend::game::Game,
dev_team: &backend::team::Team,
) -> GlobalResult<models::GameSummary> {
Ok(models::GameSummary {
) -> GlobalResult<models::GameGameSummary> {
Ok(models::GameGameSummary {
game_id: unwrap_ref!(game.game_id).as_uuid(),
name_id: game.name_id.to_owned(),
display_name: game.display_name.to_owned(),
Expand Down
4 changes: 2 additions & 2 deletions packages/common/convert/src/convert/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn summary(
team: &backend::team::Team,
team_member_counts: &[team::member_count::response::Team],
is_current_identity_member: bool,
) -> GlobalResult<models::GroupSummary> {
) -> GlobalResult<models::GroupGroupSummary> {
let team_id_proto = unwrap_ref!(team.team_id);

let member_count = unwrap!(team_member_counts
Expand All @@ -39,7 +39,7 @@ pub fn summary(
let team_id = team_id_proto.as_uuid();
let owner_user_id = unwrap_ref!(team.owner_user_id).as_uuid();

Ok(models::GroupSummary {
Ok(models::GroupGroupSummary {
group_id: team_id,
display_name: team.display_name.clone(),
bio: team.bio.clone(),
Expand Down
2 changes: 1 addition & 1 deletion packages/common/convert/src/fetch/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::convert;
pub async fn summaries(
ctx: &OperationContext<()>,
game_ids: Vec<Uuid>,
) -> GlobalResult<Vec<models::GameSummary>> {
) -> GlobalResult<Vec<models::GameGameSummary>> {
if game_ids.is_empty() {
return Ok(Vec::new());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/convert/src/fetch/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub async fn summaries(
ctx: &OperationContext<()>,
current_user_id: Option<Uuid>,
group_ids: Vec<Uuid>,
) -> GlobalResult<Vec<models::GroupSummary>> {
) -> GlobalResult<Vec<models::GroupGroupSummary>> {
if group_ids.is_empty() {
return Ok(Vec::new());
}
Expand Down
8 changes: 4 additions & 4 deletions packages/common/convert/src/impls/cloud/version/cdn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use rivet_operation::prelude::*;

use crate::{ApiTryFrom, ApiTryInto};

impl ApiTryFrom<models::CloudVersionCdnConfig> for backend::cdn::VersionConfig {
impl ApiTryFrom<models::CloudVersionCdnCdnConfig> for backend::cdn::VersionConfig {
type Error = GlobalError;

fn api_try_from(value: models::CloudVersionCdnConfig) -> GlobalResult<Self> {
fn api_try_from(value: models::CloudVersionCdnCdnConfig) -> GlobalResult<Self> {
Ok(backend::cdn::VersionConfig {
site_id: value.site_id.map(Into::into),
routes: value
Expand Down Expand Up @@ -92,13 +92,13 @@ impl ApiTryFrom<models::CloudVersionCdnHeader> for backend::cdn::custom_headers_
}
}

impl ApiTryFrom<backend::cdn::VersionConfig> for models::CloudVersionCdnConfig {
impl ApiTryFrom<backend::cdn::VersionConfig> for models::CloudVersionCdnCdnConfig {
type Error = GlobalError;

fn api_try_from(value: backend::cdn::VersionConfig) -> GlobalResult<Self> {
let site_id = unwrap_ref!(value.site_id).as_uuid();

Ok(models::CloudVersionCdnConfig {
Ok(models::CloudVersionCdnCdnConfig {
build_command: None,
build_output: None,
build_env: None,
Expand Down
8 changes: 4 additions & 4 deletions packages/common/convert/src/impls/cloud/version/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use rivet_operation::prelude::*;

use crate::{ApiTryFrom, ApiTryInto};

impl ApiTryFrom<models::CloudVersionIdentityConfig> for backend::identity::VersionConfig {
impl ApiTryFrom<models::CloudVersionIdentityIdentityConfig> for backend::identity::VersionConfig {
type Error = GlobalError;

fn api_try_from(value: models::CloudVersionIdentityConfig) -> GlobalResult<Self> {
fn api_try_from(value: models::CloudVersionIdentityIdentityConfig) -> GlobalResult<Self> {
Ok(backend::identity::VersionConfig {
custom_display_names: value
.custom_display_names
Expand Down Expand Up @@ -57,11 +57,11 @@ impl ApiTryFrom<models::CloudVersionIdentityCustomAvatar> for backend::identity:
}
}

impl ApiTryFrom<backend::identity::VersionConfig> for models::CloudVersionIdentityConfig {
impl ApiTryFrom<backend::identity::VersionConfig> for models::CloudVersionIdentityIdentityConfig {
type Error = GlobalError;

fn api_try_from(value: backend::identity::VersionConfig) -> GlobalResult<Self> {
Ok(models::CloudVersionIdentityConfig {
Ok(models::CloudVersionIdentityIdentityConfig {
display_names: Some(
value
.custom_display_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{ApiFrom, ApiInto, ApiTryFrom, ApiTryInto};
pub fn game_mode_to_proto(
name_id: String,
game_mode: &models::CloudVersionMatchmakerGameMode,
matchmaker: &models::CloudVersionMatchmakerConfig,
matchmaker: &models::CloudVersionMatchmakerMatchmakerConfig,
all_regions: &[backend::region::Region],
) -> GlobalResult<backend::matchmaker::LobbyGroup> {
// Derive regions
Expand Down Expand Up @@ -278,7 +278,7 @@ fn region_to_proto(
name_id: String,
region: &models::CloudVersionMatchmakerGameModeRegion,
game_mode: &models::CloudVersionMatchmakerGameMode,
matchmaker: &models::CloudVersionMatchmakerConfig,
matchmaker: &models::CloudVersionMatchmakerMatchmakerConfig,
regions_data: &[backend::region::Region],
) -> GlobalResult<backend::matchmaker::lobby_group::Region> {
let region_id = regions_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod lobby_group;
pub async fn config_to_proto(
ctx: &OperationContext<()>,
game_id: Uuid,
value: models::CloudVersionMatchmakerConfig,
value: models::CloudVersionMatchmakerMatchmakerConfig,
) -> GlobalResult<backend::matchmaker::VersionConfig> {
// Fetch region data required to convert models
let mut all_region_name_ids = HashSet::new();
Expand Down Expand Up @@ -57,7 +57,7 @@ pub async fn config_to_proto(
pub async fn config_to_openapi(
ctx: &OperationContext<()>,
value: backend::matchmaker::VersionConfig,
) -> GlobalResult<models::CloudVersionMatchmakerConfig> {
) -> GlobalResult<models::CloudVersionMatchmakerMatchmakerConfig> {
// Fetch region data required to convert models
let all_region_ids = value
.lobby_groups
Expand All @@ -73,7 +73,7 @@ pub async fn config_to_openapi(
})
.await?;

Ok(models::CloudVersionMatchmakerConfig {
Ok(models::CloudVersionMatchmakerMatchmakerConfig {
game_modes: Some(
value
.lobby_groups
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/client/config/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::{
};

use pegboard::protocol;
use schemars::JsonSchema;
use serde::Deserialize;
use url::Url;
use schemars::JsonSchema;
use uuid::Uuid;

#[derive(Clone, Deserialize)]
Expand Down
34 changes: 23 additions & 11 deletions packages/infra/schema-generator/build.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
use std::{fs::File, path::PathBuf, io::Write};
use std::{fs::File, io::Write, path::PathBuf};

use anyhow::*;
use schemars::{JsonSchema, gen::{SchemaSettings, SchemaGenerator}};
use schemars::{
gen::{SchemaGenerator, SchemaSettings},
JsonSchema,
};

fn main() -> Result<()> {
let cwd = std::env::current_dir()?;
let docs_output_path = cwd.join("../../../docs/src/content/docs/");

let settings = SchemaSettings::draft07().with(|s| {
s.option_nullable = true;
s.option_add_null_type = false;
});
let generator = settings.into_generator();
s.option_nullable = true;
s.option_add_null_type = false;
});
let generator = settings.into_generator();

generate_spec::<rivet_config::config::server::Server>(generator.clone(), docs_output_path.join("self-hosting/server-spec.json"))?;
generate_spec::<pegboard_config::Client>(generator.clone(), docs_output_path.join("self-hosting/client-spec.json"))?;
generate_spec::<rivet_toolchain::config::Root>(generator.clone(), docs_output_path.join("toolchain-spec.json"))?;
generate_spec::<rivet_config::config::server::Server>(
generator.clone(),
docs_output_path.join("self-hosting/server-spec.json"),
)?;
generate_spec::<pegboard_config::Client>(
generator.clone(),
docs_output_path.join("self-hosting/client-spec.json"),
)?;
generate_spec::<rivet_toolchain::config::Root>(
generator.clone(),
docs_output_path.join("toolchain-spec.json"),
)?;

Ok(())
}

fn generate_spec<T: JsonSchema>(generator: SchemaGenerator, path: PathBuf) -> Result<()> {
let schema = generator.into_root_schema_for::<T>();
let schema_text = serde_json::to_string_pretty(&schema)?;

let mut file = File::create(path)?;
file.write_all(schema_text.as_bytes())?;

Ok(())
}
}
1 change: 1 addition & 0 deletions packages/infra/schema-generator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion packages/services/ds/src/workflows/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ async fn get_server_meta(
let project_id = unwrap!(env.game_id).as_uuid();
let projects_res = op!([ctx] game_get {
game_ids: vec![project_id.into()],
}).await?;
})
.await?;
let project = unwrap!(projects_res.games.first());

Ok(GetServerMetaOutput {
Expand Down
3 changes: 1 addition & 2 deletions packages/toolchain/cli/src/commands/actor/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use clap::{Parser, ValueEnum};
use serde::Deserialize;
use std::collections::HashMap;
use toolchain::{
build,
build, errors,
rivet_api::{apis, models},
errors,
};
use uuid::Uuid;

Expand Down
12 changes: 6 additions & 6 deletions packages/toolchain/cli/src/commands/manager/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use anyhow::*;
use clap::Parser;
use toolchain::tasks::manager::get_endpoint;

use crate::util::{
task::{run_task, TaskOutputStyle},
};
use crate::util::task::{run_task, TaskOutputStyle};

#[derive(Parser)]
pub struct Opts {
Expand All @@ -16,9 +14,11 @@ impl Opts {
pub async fn execute(&self) -> Result<()> {
let ctx = toolchain::toolchain_ctx::load().await?;
let env = crate::util::env::get_or_select(&ctx, self.environment.as_ref()).await?;
let res =
run_task::<get_endpoint::Task>(TaskOutputStyle::None, get_endpoint::Input { env_slug: env })
.await?;
let res = run_task::<get_endpoint::Task>(
TaskOutputStyle::None,
get_endpoint::Input { env_slug: env },
)
.await?;
println!("{}", res.endpoint);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion packages/toolchain/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub mod actor;
pub mod build;
pub mod deno;
pub mod manager;
pub mod deploy;
pub mod environment;
pub mod init;
pub mod login;
pub mod logout;
pub mod manager;
pub mod metadata;
pub mod region;

Expand Down
2 changes: 1 addition & 1 deletion packages/toolchain/toolchain/src/config/build/docker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::Compression;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::Compression;

Expand Down
2 changes: 1 addition & 1 deletion packages/toolchain/toolchain/src/config/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub mod docker;
pub mod javascript;
Expand Down
5 changes: 2 additions & 3 deletions packages/toolchain/toolchain/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{
};

use anyhow::*;
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub mod build;

Expand Down Expand Up @@ -86,12 +86,11 @@ pub struct Unstable {
#[derive(Default, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct ManagerUnstable {
pub enable: Option<bool>
pub enable: Option<bool>,
}

impl ManagerUnstable {
pub fn enable(&self) -> bool {
self.enable.unwrap_or(true)
}

}
2 changes: 1 addition & 1 deletion packages/toolchain/toolchain/src/tasks/deploy/docker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::*;
use std::collections::HashMap;
use std::path::Path;
use uuid::Uuid;
use std::collections::HashMap;

use crate::{
config, paths,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolchain/toolchain/src/tasks/deploy/js.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::*;
use futures_util::{StreamExt, TryStreamExt};
use rivet_api::{apis, models};
use std::{path::PathBuf, sync::Arc, collections::HashMap};
use std::{collections::HashMap, path::PathBuf, sync::Arc};
use tokio::fs;
use uuid::Uuid;

Expand Down
Loading

0 comments on commit 4707547

Please sign in to comment.