From b805ee3a8244c3eafdf862b9e64a768c13e543fa Mon Sep 17 00:00:00 2001 From: andres Date: Thu, 17 Oct 2024 17:30:51 -0500 Subject: [PATCH] chore: Cran suggestions --- DESCRIPTION | 2 ++ R/http_helpers.R | 24 ++++++++++++------------ R/response_builder.R | 16 ++++++++-------- R/service.R | 11 ++++++----- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c429df1..d3c57a1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,6 +11,8 @@ Description: The best way to implement middle ware for 'shiny' Applications. 'to model for incoming HTTP requests and server sessions. 'tower' is a very minimal package with little overhead, it is mainly meant for other package developers to implement new behavior. +URL: https://github.com/ixpantia/tower +BugReports: https://github.com/ixpantia/tower/issues License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/http_helpers.R b/R/http_helpers.R index a4b2b4c..20fe2db 100644 --- a/R/http_helpers.R +++ b/R/http_helpers.R @@ -4,7 +4,7 @@ #' @param method A string containing the HTTP method to match #' @param path A string containing the path to match #' @param handler A function to call when the layer is matched -#' @return A tower object with the layer added +#' @value The tower with the added route #' @export add_route <- function(tower, method = "GET", path, handler) { handler <- compiler::cmpfun(handler) @@ -22,7 +22,7 @@ add_route <- function(tower, method = "GET", path, handler) { #' @param tower A tower object #' @param path A string containing the path to match #' @param handler A function to call when the route is matched -#' @return A tower object with the route added +#' @value The tower with the added GET route #' @export add_get_route <- function(tower, path, handler) { add_route(tower, "GET", path, handler) @@ -33,7 +33,7 @@ add_get_route <- function(tower, path, handler) { #' @param tower A tower object #' @param path A string containing the path to match #' @param handler A function to call when the route is matched -#' @return A tower object with the route added +#' @value The tower with the added POST route #' @export add_post_route <- function(tower, path, handler) { add_route(tower, "POST", path, handler) @@ -44,7 +44,7 @@ add_post_route <- function(tower, path, handler) { #' @param tower A tower object #' @param path A string containing the path to match #' @param handler A function to call when the route is matched -#' @return A tower object with the route added +#' @value The tower with the added PUT route #' @export add_put_route <- function(tower, path, handler) { add_route(tower, "PUT", path, handler) @@ -55,7 +55,7 @@ add_put_route <- function(tower, path, handler) { #' @param tower A tower object #' @param path A string containing the path to match #' @param handler A function to call when the route is matched -#' @return A tower object with the route added +#' @value The tower with the added DELETE route #' @export add_delete_route <- function(tower, path, handler) { add_route(tower, "DELETE", path, handler) @@ -66,7 +66,7 @@ add_delete_route <- function(tower, path, handler) { #' @param tower A tower object #' @param path A string containing the path to match #' @param handler A function to call when the route is matched -#' @return A tower object with the route added +#' @value The tower with the added PATCH route #' @export add_patch_route <- function(tower, path, handler) { add_route(tower, "PATCH", path, handler) @@ -78,7 +78,7 @@ add_patch_route <- function(tower, path, handler) { #' @param ... Additional arguments to pass to \code{\link[jsonlite]{fromJSON}} #' when parsing the request body. This will only be used the first time the #' request body is parsed. Subsequent calls will return the cached result. -#' @return A list containing the request body +#' @value The R object representation of the body's JSON content #' @export req_body_json <- function(req, ...) { if (!is.null(req[[".parsed.body.json"]])) { @@ -100,7 +100,7 @@ req_body_json <- function(req, ...) { #' @title Extract form data from a request #' @description Extracts form data from a request #' @param req A request object -#' @return A list containing the form data +#' @value A list containing the form data in the body #' @export req_body_form <- function(req) { if (!is.null(req[[".parsed.body.form"]])) { @@ -120,7 +120,7 @@ req_body_form <- function(req) { #' @title Extract query parameters from a request #' @description Extracts query parameters from a request #' @param req A request object -#' @return A list containing the query parameters +#' @value A list containing the query parameters #' @export req_query <- function(req) { if (!is.null(req[[".parsed.query"]])) { @@ -152,7 +152,7 @@ cookie_unescape <- function(.x) { #' #' @param x A string containing the cookies #' -#' @return A list containing the cookies +#' @value A list containing the HTTP cookies #' @keywords internal parse_cookies <- function(x) { if (is.null(x)) { @@ -178,7 +178,7 @@ cookie_to_header <- function(.x, .y) { #' @param key A string containing the cookie key #' @param value A string containing the cookie value #' -#' @return A string containing the cookie +#' @value A string containing the formated cookie #' @export build_http_cookie <- function(key, value) { glue::glue("{key}={value}; path=/; SameSite=Lax; HttpOnly") @@ -187,7 +187,7 @@ build_http_cookie <- function(key, value) { #' @title Extract cookies from a request #' @description Extracts cookies from a request #' @param req A request object -#' @return A list containing the cookies +#' @value A list containing the cookies #' @export req_cookies <- function(req) { if (!is.null(req[[".parsed.cookies"]])) { diff --git a/R/response_builder.R b/R/response_builder.R index b986ca0..271bf8f 100644 --- a/R/response_builder.R +++ b/R/response_builder.R @@ -1,6 +1,6 @@ #' @title Create a response builder #' @description Creates a response builder -#' @return A response builder object +#' @value A response builder object #' @export response_builder <- function() { resp <- new.env(parent = emptyenv()) @@ -20,7 +20,7 @@ response_builder <- function() { #' @param res A response builder object #' @param name The name of the header #' @param value The value of the header -#' @return The response builder object +#' @value The response builder object #' @export set_header <- function(res, name, value) { res$headers[[name]] <- value @@ -31,7 +31,7 @@ set_header <- function(res, name, value) { #' @description Sets the status of a response #' @param res A response builder object #' @param status The status to set -#' @return The response builder object +#' @value The response builder object #' @export set_status <- function(res, status) { res$status <- status @@ -43,7 +43,7 @@ set_status <- function(res, status) { #' @param res A response builder object #' @param name The name of the cookie #' @param value The value of the cookie -#' @return The response builder object +#' @value The response builder object #' @export add_cookie <- function(res, name, value) { res$cookies[[name]] <- value @@ -54,7 +54,7 @@ add_cookie <- function(res, name, value) { #' @description Sets the content type of a response #' @param res A response builder object #' @param content_type The content type to set -#' @return The response builder object +#' @value The response builder object #' @export set_content_type <- function(res, content_type) { res$content_type <- content_type @@ -111,7 +111,7 @@ serialize_body <- function(body, content_type) { #' @description Adds a body to a response, if no content type is set, it will be detected #' @param res A response builder object #' @param body The body to add -#' @return The response builder object +#' @value The response builder object #' @export add_body <- function(res, body) { if (is.null(res$content_type)) { @@ -125,7 +125,7 @@ add_body <- function(res, body) { #' @description Adds a body to a response as JSON #' @param res A response builder object #' @param body The body to add -#' @return The response builder object +#' @value The response builder object #' @export add_body_json <- function(res, body) { set_content_type(res, "application/json") @@ -136,7 +136,7 @@ add_body_json <- function(res, body) { #' @title Build a response #' @description Builds a response #' @param res A response builder object -#' @return A response object +#' @value A 'shiny' response object #' @export build_response <- function(res) { content_type <- ifelse( diff --git a/R/service.R b/R/service.R index 4ec1a31..4688f02 100644 --- a/R/service.R +++ b/R/service.R @@ -4,7 +4,7 @@ compiler_options <- list(optimize = 3L) #' @title Create a new tower #' @description Create a new tower to build upon. #' @param app A 'shiny' app object -#' @return A new tower +#' @value A new tower object to add more layers to #' @export create_tower <- function(app) { structure( @@ -21,6 +21,7 @@ create_tower <- function(app) { #' @description Print a tower #' @param x A tower #' @param ... Ignored arguments (for compatibility with print) +#' @value No return value, called for side effects #' @export print.tower <- function(x, ...) { cat( @@ -37,7 +38,7 @@ print.tower <- function(x, ...) { #' a response. A layer can short circuit by returning a response #' directly or call the next layer will `req$NEXT(req)` which #' will call the next layer in the middleware. -#' @return The tower with the layer added +#' @value The tower with the added layer #' @export add_http_layer <- function(tower, layer) { tower$http_layers <- c( @@ -57,7 +58,7 @@ add_http_layer <- function(tower, layer) { #' and has no return value. This function will be called before #' the original server function. If you want to short-circuit #' the server use an exception. -#' @return The tower with the layer added +#' @value The tower with the added layer #' @export add_server_layer <- function(tower, layer) { tower$server_layers <- c( @@ -137,7 +138,7 @@ build_server <- function(tower) { #' @description Build a 'shiny' app from a tower. This will create #' a new 'shiny' app with the specified layers added. #' @param tower A tower -#' @return A 'shiny' app object that can be started +#' @value A 'shiny' app object that can be started #' @export build_tower <- function(tower) { app <- tower$app @@ -149,7 +150,7 @@ build_tower <- function(tower) { #' @title Into parts #' @description Splits a shiny.appobj into its parts, the ui and server #' @param app A shiny.appobj -#' @return A list with the ui and server handlers +#' @value A list with the ui and server handlers #' @export app_into_parts <- function(app) { ui <- app$httpHandler