Skip to content
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
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["network-programming", "web-programming"]
exclude.workspace = true

[workspace.package]
version = "21.12.1"
version = "21.13.0"
readme = "README.md"
edition = "2024"
authors = ["root@ltpp.vip"]
Expand All @@ -25,15 +25,15 @@ resolver = "2"
members = ["compress", "constant", "type", "request", "core", "macros", "cli", "plugin/websocket"]

[workspace.dependencies]
hyperlane = { path = ".", version = "21.12.1" }
http-type = { path = "type", version = "21.12.1" }
hyperlane-cli = { path = "cli", version = "21.12.1" }
hyperlane-core = { path = "core", version = "21.12.1" }
http-request = { path = "request", version = "21.12.1" }
http-compress = { path = "compress", version = "21.12.1" }
http-constant = { path = "constant", version = "21.12.1" }
hyperlane-macros = { path = "macros", version = "21.12.1" }
hyperlane-plugin-websocket = { path = "plugin/websocket", version = "21.12.1" }
hyperlane = { path = ".", version = "21.13.0" }
http-type = { path = "type", version = "21.13.0" }
hyperlane-cli = { path = "cli", version = "21.13.0" }
hyperlane-core = { path = "core", version = "21.13.0" }
http-request = { path = "request", version = "21.13.0" }
http-compress = { path = "compress", version = "21.13.0" }
http-constant = { path = "constant", version = "21.13.0" }
hyperlane-macros = { path = "macros", version = "21.13.0" }
hyperlane-plugin-websocket = { path = "plugin/websocket", version = "21.13.0" }

hex = "0.4.3"
md5 = "0.8.1"
Expand Down
10 changes: 9 additions & 1 deletion cli/src/config/struct.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
use super::*;

/// Parsed command line arguments
#[derive(Clone, Debug)]
///
/// `hyperlane-cli` ships both a library and a `hyperlane` binary; the binary
/// is a separate crate that consumes this one, so the read path must stay
/// `pub` (§17.14 does not recall published API).
#[derive(Clone, Data, Debug)]
pub struct Args {
/// The command to execute
pub command: CommandType,
/// Project name for new command
#[get(type(clone))]
pub project_name: Option<String>,
/// Template type for template command
#[get(type(clone))]
pub template_type: Option<TemplateType>,
/// Model subtype for template command (only when template_type is Model)
#[get(type(clone))]
pub model_sub_type: Option<ModelSubType>,
/// Component name for template command
#[get(type(clone))]
pub component_name: Option<String>,
}
12 changes: 6 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use std::process::exit;
async fn main() {
Logger::init(log::LevelFilter::Info);
let args: Args = parse_args();
match args.command {
match args.get_command() {
CommandType::Watch => {
if let Err(error) = execute_watch().await {
log::error!("watch failed: {error}");
exit(1);
}
}
CommandType::New => {
if let Some(project_name) = args.project_name {
if let Some(project_name) = args.get_project_name() {
if let Err(error) = execute_new(&project_name).await {
log::error!("new failed: {error}");
exit(1);
Expand All @@ -30,7 +30,7 @@ async fn main() {
}
}
CommandType::Template => {
let template_type: TemplateType = match args.template_type {
let template_type: TemplateType = match args.get_template_type() {
Some(tt) => tt,
None => {
log::error!(
Expand All @@ -39,7 +39,7 @@ async fn main() {
exit(1);
}
};
let component_name: String = match args.component_name {
let component_name: String = match args.get_component_name() {
Some(cn) => cn,
None => {
log::error!(
Expand All @@ -48,12 +48,12 @@ async fn main() {
exit(1);
}
};
if template_type == TemplateType::Model && args.model_sub_type.is_none() {
if template_type == TemplateType::Model && args.get_model_sub_type().is_none() {
log::error!("Error: Model type requires subtype (application|request|response)");
exit(1);
}
if let Err(error) =
execute_template(template_type, &component_name, args.model_sub_type).await
execute_template(template_type, &component_name, args.get_model_sub_type()).await
{
log::error!("template failed: {error}");
exit(1);
Expand Down
4 changes: 3 additions & 1 deletion cli/src/new/struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;

/// Configuration for creating a new project
#[derive(Clone, Debug)]
#[derive(Clone, Data, Debug)]
pub struct NewProjectConfig {
/// Name of the project to create
pub project_name: String,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/template/struct.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

/// Configuration for template generation
#[derive(Clone, Debug)]
#[derive(Clone, Data, Debug)]
pub struct TemplateConfig {
/// Type of template component to generate
pub template_type: TemplateType,
Expand Down
2 changes: 1 addition & 1 deletion core/src/hook/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct ServerControlHook {
/// the application exits.
#[debug(skip)]
#[set(pub(crate))]
pub(super) wait_hook: ServerControlHookHandler<()>,
pub(crate) wait_hook: ServerControlHookHandler<()>,
/// A hook that, when called, initiates a graceful shutdown of the server.
/// This will stop the server from accepting new connections and allow existing ones
/// to complete.
Expand Down
16 changes: 8 additions & 8 deletions core/tests/server/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use super::*;
pub(crate) struct TestSendRoute;

pub(crate) struct TaskPanicHook {
pub(crate) response_body: String,
pub(crate) content_type: String,
pub(super) response_body: String,
pub(super) content_type: String,
}

pub(crate) struct RequestErrorHook {
pub(crate) response_status_code: ResponseStatusCode,
pub(crate) response_body: String,
pub(super) response_status_code: ResponseStatusCode,
pub(super) response_body: String,
}

pub(crate) struct RequestMiddleware {
Expand All @@ -21,17 +21,17 @@ pub(crate) struct UpgradeMiddleware;
pub(crate) struct ResponseMiddleware;

pub(crate) struct RootRoute {
pub(crate) response_body: String,
pub(crate) cookie1: String,
pub(crate) cookie2: String,
pub(super) response_body: String,
pub(super) cookie1: String,
pub(super) cookie2: String,
}

pub(crate) struct SseRoute;

pub(crate) struct WebsocketRoute;

pub(crate) struct DynamicRoute {
pub(crate) params: RouteParams,
pub(super) params: RouteParams,
}

pub(crate) struct GetAllRoutes;
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3216,7 +3216,7 @@ pub fn try_get_request_query(attr: TokenStream, item: TokenStream) -> TokenStrea
///
/// #[prologue_macros(
/// request_query("test" => request_query),
/// response_body(&format!("request query: {request_query}")),
/// response_body(&format!("request query: {request_query:?}")),
/// send
/// )]
/// async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
Expand Down
1 change: 1 addition & 0 deletions plugin/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ exclude.workspace = true
[dependencies]
hyperlane = { workspace = true }

lombok-macros = { workspace = true }
tokio-broadcast = { workspace = true }
93 changes: 0 additions & 93 deletions plugin/websocket/src/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,46 +390,6 @@ where
self
}

/// Returns a mutable reference to the stream served by this configuration.
///
/// # Returns
///
/// - `&mut Stream` - A mutable reference to the stream.
#[inline(always)]
pub fn get_stream(&mut self) -> &mut Stream {
self.stream
}

/// Retrieves a reference to the context associated with this configuration.
///
/// # Returns
///
/// - `&mut Context` - A reference to the context object.
#[inline(always)]
pub fn get_context(&mut self) -> &mut Context {
self.context
}

/// Retrieves the capacity configured for the broadcast sender.
///
/// # Returns
///
/// - `Capacity` - The capacity.
#[inline(always)]
pub fn get_capacity(&self) -> Capacity {
self.capacity
}

/// Retrieves a reference to the broadcast type configured for this WebSocket.
///
/// # Returns
///
/// - `&BroadcastType<B>` - A reference to the broadcast type object.
#[inline(always)]
pub fn get_broadcast_type(&self) -> &BroadcastType<B> {
&self.broadcast_type
}

/// Sets the connected hook handler.
///
/// This hook is executed when the WebSocket connection is established.
Expand Down Expand Up @@ -561,46 +521,6 @@ where
self.closed_hook = Hook::factory::<S>();
self
}

/// Retrieves a reference to the connected hook handler.
///
/// # Returns
///
/// - `&ServerHookHandler` - A reference to the connected hook handler.
#[inline(always)]
pub fn get_connected_hook(&self) -> &ServerHookHandler {
&self.connected_hook
}

/// Retrieves a reference to the request hook handler.
///
/// # Returns
///
/// - `&ServerHookHandler` - A reference to the request hook handler.
#[inline(always)]
pub fn get_request_hook(&self) -> &ServerHookHandler {
&self.request_hook
}

/// Retrieves a reference to the sended hook handler.
///
/// # Returns
///
/// - `&ServerHookHandler` - A reference to the sended hook handler.
#[inline(always)]
pub fn get_sended_hook(&self) -> &ServerHookHandler {
&self.sended_hook
}

/// Retrieves a reference to the closed hook handler.
///
/// # Returns
///
/// - `&ServerHookHandler` - A reference to the closed hook handler.
#[inline(always)]
pub fn get_closed_hook(&self) -> &ServerHookHandler {
&self.closed_hook
}
}

impl WebSocket {
Expand All @@ -616,19 +536,6 @@ impl WebSocket {
Self::default()
}

/// Returns a shared reference to the internal broadcast map.
///
/// Hand-written accessor: the `WebSocket` struct does not derive the lombok
/// `Data` macro, and §17.3 forbids reading `self.broadcast_map` directly.
///
/// # Returns
///
/// - `&BroadcastMap<Vec<u8>>` - A shared reference to the internal broadcast map.
#[inline(always)]
pub fn get_broadcast_map(&self) -> &BroadcastMap<Vec<u8>> {
&self.broadcast_map
}

/// Subscribes to a broadcast type or inserts a new one if it doesn't exist.
///
/// # Type Parameters
Expand Down
1 change: 1 addition & 0 deletions plugin/websocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ use {
tokio::sync::broadcast::{Receiver, error::SendError},
*,
},
lombok_macros::*,
tokio_broadcast::*,
};
12 changes: 11 additions & 1 deletion plugin/websocket/src/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
///
/// This struct manages broadcast capabilities and holds the internal broadcast map
/// responsible for handling message distribution to various WebSocket connections.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Data, Debug, Default)]
pub struct WebSocket {
/// The internal broadcast map.
///
Expand All @@ -21,36 +21,46 @@ pub struct WebSocket {
/// # Type Parameters
///
/// - `B`: The type used for broadcast keys, which must implement `BroadcastTypeTrait`.
#[derive(Data)]
pub struct WebSocketConfig<'a, B: BroadcastTypeTrait> {
/// The underlying stream for this WebSocket connection.
#[set(skip)]
pub(super) stream: &'a mut Stream,
/// The Hyperlane context.
///
/// This context is associated with this WebSocket connection.
#[set(skip)]
pub(super) context: &'a mut Context,
/// The capacity.
///
/// This is the capacity of the broadcast sender channel.
#[get(type(copy))]
#[set(skip)]
pub(super) capacity: Capacity,
/// The broadcast type.
///
/// This defines the type of broadcast this WebSocket connection will participate in
/// (point-to-point or point-to-group).
#[set(skip)]
pub(super) broadcast_type: BroadcastType<B>,
/// The connected hook handler.
///
/// This hook is executed when the WebSocket connection is established.
#[set(skip)]
pub(super) connected_hook: ServerHookHandler,
/// The request hook handler.
///
/// This hook is executed when a new request is received on the WebSocket.
#[set(skip)]
pub(super) request_hook: ServerHookHandler,
/// The sended hook handler.
///
/// This hook is executed after a message has been successfully sent over the WebSocket.
#[set(skip)]
pub(super) sended_hook: ServerHookHandler,
/// The closed hook handler.
///
/// This hook is executed when the WebSocket connection is closed.
#[set(skip)]
pub(super) closed_hook: ServerHookHandler,
}
Loading
Loading