Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-3558: harpc: rename Metadata to SubsystemInformation and ProcedureInformation #5599

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions apps/hash-graph/libs/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 apps/hash-graph/libs/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 apps/hash-graph/libs/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 @@ -24,7 +24,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>,
}
50 changes: 47 additions & 3 deletions libs/@local/harpc/service/src/procedure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use frunk::HCons;
use harpc_types::procedure::{ProcedureDescriptor, ProcedureId};
use harpc_types::{
procedure::{ProcedureDescriptor, ProcedureId},
version::Version,
};

use crate::{Subsystem, metadata::Metadata};
use crate::{Subsystem, metadata::Deprecation};

/// A marker trait for procedures that are included in a service.
///
Expand All @@ -20,17 +23,58 @@ pub trait ProcedureIdentifier: Sized {
fn into_id(self) -> ProcedureId;
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ProcedureInformation {
pub descriptor: ProcedureDescriptor,

/// The version at which the procedure was introduced.
pub since: Version,

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

pub trait Procedure: Sized {
type Subsystem: Subsystem<Procedures: IncludesProcedure<Self>>;

const ID: <Self::Subsystem as Subsystem>::ProcedureId;

/// Returns the descriptor for this procedure.
#[must_use]
fn descriptor() -> ProcedureDescriptor {
ProcedureDescriptor {
id: Self::ID.into_id(),
}
}

fn metadata() -> Metadata;
/// Returns the version at which this procedure was introduced.
///
/// By default, this returns the initial version of the subsystem.
/// Override this method to specify a different introduction version.
#[must_use]
fn since() -> Version {
Self::Subsystem::initial_version()
}

/// Returns the deprecation information for this procedure.
///
/// 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 procedure.
///
/// This method aggregates the descriptor, introduction version, and deprecation status
/// of the procedure into a single `ProcedureInformation` struct.
#[must_use]
fn information() -> ProcedureInformation {
ProcedureInformation {
descriptor: Self::descriptor(),
since: Self::since(),
deprecation: Self::deprecation(),
}
}
}
Loading