Skip to content

Commit

Permalink
Merge pull request #5191 from systeminit/migrate-modules-to-v2
Browse files Browse the repository at this point in the history
chore(sdf): Migrate list_modules to v2 endpoint
  • Loading branch information
stack72 authored Dec 23, 2024
2 parents 82dfcfa + 697578d commit 2e02498
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 53 deletions.
8 changes: 4 additions & 4 deletions app/web/src/store/module.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ export const useModuleStore = () => {
},

async LOAD_LOCAL_MODULES() {
return new ApiRequest<{ modules: LocalModuleSummary[] }>({
url: "/module/list_modules",
params: { ...getVisibilityParams() },
return new ApiRequest<LocalModuleSummary[]>({
method: "get",
url: API_PREFIX,
onSuccess: (response) => {
// TODO: remove this
// the backend currently needs the full tar file name
// but we want the actual name in the module metadata
// easier to strip off temporarily but we'll need to change what the backend is storing
const modulesWithNamesFixed = _.map(response.modules, (m) => ({
const modulesWithNamesFixed = _.map(response, (m) => ({
...m,
name: m.name.replace(/-\d\d\d\d-\d\d-\d\d\.sipkg/, ""),
}));
Expand Down
2 changes: 0 additions & 2 deletions lib/sdf-server/src/service/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub mod get_module;
pub mod import_workspace_vote;
pub mod install_module;
mod install_workspace;
pub mod list_modules;
pub mod reject_module;
pub mod remote_module_spec;

Expand Down Expand Up @@ -254,7 +253,6 @@ pub fn routes() -> Router<AppState> {
"/install_workspace",
post(install_workspace::install_workspace),
)
.route("/list_modules", get(list_modules::list_modules))
.route(
"/remote_module_spec",
get(remote_module_spec::remote_module_spec),
Expand Down
46 changes: 0 additions & 46 deletions lib/sdf-server/src/service/module/list_modules.rs

This file was deleted.

4 changes: 4 additions & 0 deletions lib/sdf-server/src/service/v2/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use thiserror::Error;
use crate::{service::ApiError, AppState};

mod contribute;
mod list;
mod sync;

pub type ModuleAPIResult<T> = Result<T, ModulesAPIError>;

#[remain::sorted]
#[derive(Debug, Error)]
pub enum ModulesAPIError {
Expand Down Expand Up @@ -57,4 +60,5 @@ pub fn v2_routes() -> Router<AppState> {
Router::new()
.route("/contribute", post(contribute::contribute))
.route("/sync", get(sync::sync))
.route("/", get(list::list))
}
35 changes: 35 additions & 0 deletions lib/sdf-server/src/service/v2/module/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use axum::{
extract::{Host, OriginalUri, Path},
Json,
};
use dal::{module::Module, ChangeSetId, WorkspacePk};
use si_frontend_types::ModuleSummary;

use super::ModuleAPIResult;
use crate::extract::{AccessBuilder, HandlerContext, PosthogClient, RawAccessToken};

pub async fn list(
HandlerContext(builder): HandlerContext,
AccessBuilder(access_builder): AccessBuilder,
RawAccessToken(_raw_access_token): RawAccessToken,
PosthogClient(_posthog_client): PosthogClient,
OriginalUri(_original_uri): OriginalUri,
Host(_host_name): Host,
Path((_workspace_pk, change_set_id)): Path<(WorkspacePk, ChangeSetId)>,
) -> ModuleAPIResult<Json<Vec<ModuleSummary>>> {
let ctx = builder
.build(access_builder.build(change_set_id.into()))
.await?;

let installed_modules = Module::list_installed(&ctx).await?;

let modules: Vec<ModuleSummary> = installed_modules
.iter()
.map(|module| ModuleSummary {
name: module.name().to_owned(),
hash: module.root_hash().to_string(),
})
.collect();

Ok(Json(modules))
}
3 changes: 2 additions & 1 deletion lib/si-frontend-types-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub use crate::func::{
FuncSummary, LeafInputLocation,
};
pub use crate::module::{
BuiltinModules, LatestModule, ModuleContributeRequest, ModuleDetails, SyncedModules,
BuiltinModules, LatestModule, ModuleContributeRequest, ModuleDetails, ModuleSummary,
SyncedModules,
};
pub use crate::schema_variant::{
ComponentType, InputSocket, OutputSocket, Prop, PropKind, SchemaVariant, UninstalledVariant,
Expand Down
7 changes: 7 additions & 0 deletions lib/si-frontend-types-rs/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ pub struct ModuleContributeRequest {
pub version: String,
pub schema_variant_id: SchemaVariantId,
}

#[derive(Clone, Debug, Deserialize, Eq, Serialize, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct ModuleSummary {
pub name: String,
pub hash: String,
}

0 comments on commit 2e02498

Please sign in to comment.