Skip to content

Commit

Permalink
Merge branch 'main' into t/h-3564-use-consistent-library-structure-fo…
Browse files Browse the repository at this point in the history
…r-rust-crates
  • Loading branch information
TimDiekmann committed Nov 7, 2024
2 parents 50b0ea0 + 93c0530 commit 2be309f
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 261 deletions.
6 changes: 3 additions & 3 deletions apps/hash-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"@mailchimp/mailchimp_marketing": "3.0.80",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/core": "1.27.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.54.1",
"@opentelemetry/instrumentation": "0.54.1",
"@opentelemetry/exporter-trace-otlp-grpc": "0.54.2",
"@opentelemetry/instrumentation": "0.54.2",
"@opentelemetry/instrumentation-express": "0.44.0",
"@opentelemetry/instrumentation-graphql": "0.44.0",
"@opentelemetry/instrumentation-http": "0.54.1",
"@opentelemetry/instrumentation-http": "0.54.2",
"@opentelemetry/resources": "1.27.0",
"@opentelemetry/sdk-trace-base": "1.27.0",
"@opentelemetry/sdk-trace-node": "1.27.0",
Expand Down
61 changes: 0 additions & 61 deletions libs/@local/graph/api/src/rpc/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ pub mod meta {
use frunk::HList;
use harpc_service::{
Subsystem,
metadata::Metadata,
procedure::{Procedure, ProcedureIdentifier},
};
use harpc_types::{procedure::ProcedureId, version::Version};
Expand Down Expand Up @@ -158,16 +157,6 @@ pub mod meta {
major: 0x00,
minor: 0x00,
};

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureCreateAccount;
Expand All @@ -176,16 +165,6 @@ pub mod meta {
type Subsystem = AccountSystem;

const ID: <Self::Subsystem as Subsystem>::ProcedureId = AccountProcedureId::CreateAccount;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureCreateAccountGroup;
Expand All @@ -195,16 +174,6 @@ pub mod meta {

const ID: <Self::Subsystem as Subsystem>::ProcedureId =
AccountProcedureId::CreateAccountGroup;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureCheckAccountGroupPermission;
Expand All @@ -214,16 +183,6 @@ pub mod meta {

const ID: <Self::Subsystem as Subsystem>::ProcedureId =
AccountProcedureId::CheckAccountGroupPermission;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureAddAccountGroupMember;
Expand All @@ -233,16 +192,6 @@ pub mod meta {

const ID: <Self::Subsystem as Subsystem>::ProcedureId =
AccountProcedureId::AddAccountGroupMember;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureRemoveAccountGroupMember;
Expand All @@ -252,16 +201,6 @@ pub mod meta {

const ID: <Self::Subsystem as Subsystem>::ProcedureId =
AccountProcedureId::RemoveAccountGroupMember;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}
}

Expand Down
21 changes: 0 additions & 21 deletions libs/@local/graph/api/src/rpc/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub mod meta {
use frunk::HList;
use harpc_service::{
Subsystem,
metadata::Metadata,
procedure::{Procedure, ProcedureIdentifier},
};
use harpc_types::{procedure::ProcedureId, version::Version};
Expand Down Expand Up @@ -78,16 +77,6 @@ pub mod meta {
major: 0x00,
minor: 0x00,
};

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureAuthenticate;
Expand All @@ -97,16 +86,6 @@ pub mod meta {

const ID: <Self::Subsystem as Subsystem>::ProcedureId =
AuthenticationProcedureId::Authenticate;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}
}

Expand Down
21 changes: 0 additions & 21 deletions libs/@local/graph/api/src/rpc/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub mod meta {
use frunk::HList;
use harpc_service::{
Subsystem,
metadata::Metadata,
procedure::{Procedure, ProcedureIdentifier},
};
use harpc_types::{procedure::ProcedureId, version::Version};
Expand Down Expand Up @@ -75,16 +74,6 @@ pub mod meta {
major: 0x00,
minor: 0x00,
};

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

pub struct ProcedureEcho;
Expand All @@ -93,16 +82,6 @@ pub mod meta {
type Subsystem = EchoSystem;

const ID: <Self::Subsystem as Subsystem>::ProcedureId = EchoProcedureId::Echo;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}
}

Expand Down
21 changes: 0 additions & 21 deletions libs/@local/harpc/server/examples/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use harpc_server::{Server, ServerConfig, router::RouterBuilder, serve::serve, se
use harpc_service::{
Subsystem, SubsystemIdentifier,
delegate::SubsystemDelegate,
metadata::Metadata,
procedure::{Procedure, ProcedureIdentifier},
role,
};
Expand Down Expand Up @@ -103,16 +102,6 @@ impl Subsystem for Account {
major: 0x00,
minor: 0x00,
};

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

#[derive(serde::Serialize, serde::Deserialize)]
Expand All @@ -124,16 +113,6 @@ impl Procedure for CreateAccount {
type Subsystem = Account;

const ID: <Self::Subsystem as Subsystem>::ProcedureId = AccountProcedureId::CreateAccount;

fn metadata() -> Metadata {
Metadata {
since: Version {
major: 0x00,
minor: 0x00,
},
deprecation: None,
}
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
Expand Down
47 changes: 45 additions & 2 deletions libs/@local/harpc/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use harpc_types::{
version::Version,
};

use self::{metadata::Metadata, procedure::ProcedureIdentifier};
use self::{metadata::Deprecation, procedure::ProcedureIdentifier};

pub mod delegate;
pub mod metadata;
Expand Down Expand Up @@ -42,6 +42,15 @@ impl<Id> RefinedSubsystemIdentifier<Id> for ! {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct SubsystemInformation {
pub descriptor: SubsystemDescriptor,
/// The deprecation information for subsystem.
pub deprecation: Option<Deprecation>,
/// The initial version this subsystem was introduced in.
pub initial_version: Version,
}

pub trait Subsystem {
type SubsystemId: SubsystemIdentifier;
type ProcedureId: ProcedureIdentifier<Subsystem = Self>;
Expand All @@ -52,6 +61,7 @@ pub trait Subsystem {
const ID: Self::SubsystemId;
const VERSION: Version;

/// Returns the descriptor for this subsystem.
#[must_use]
fn descriptor() -> SubsystemDescriptor {
SubsystemDescriptor {
Expand All @@ -60,5 +70,38 @@ pub trait Subsystem {
}
}

fn metadata() -> Metadata;
/// Returns the initial version in which this subsystem was introduced.
///
/// This version represents the first release where the subsystem became available.
///
/// By default, this returns the initial version of `0.0`.
#[must_use]
fn initial_version() -> Version {
Version {
major: 0x00,
minor: 0x00,
}
}

/// Returns the deprecation information for this subsystem, if any.
///
/// By default, this returns `None`, indicating that the procedure is not deprecated.
/// Override this method to specify deprecation information.
#[must_use]
fn deprecation() -> Option<Deprecation> {
None
}

/// Returns comprehensive information about the subsystem.
///
/// This method aggregates various details about the subsystem, including its
/// descriptor, initial version, and deprecation status.
#[must_use]
fn information() -> SubsystemInformation {
SubsystemInformation {
descriptor: Self::descriptor(),
initial_version: Self::initial_version(),
deprecation: Self::deprecation(),
}
}
}
10 changes: 0 additions & 10 deletions libs/@local/harpc/service/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ pub struct Deprecation {
/// The reason for deprecation.
pub reason: Option<&'static str>,
}

/// Metadata containing version information for procedures and services.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Metadata {
/// The version at which the procedure/service was introduced.
pub since: Version,

/// The deprecation information for the procedure/service.
pub deprecation: Option<Deprecation>,
}
Loading

0 comments on commit 2be309f

Please sign in to comment.