Skip to content

Commit

Permalink
Rename WebX types
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Sep 13, 2023
1 parent cdd7048 commit c0ebbb6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/engine/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use crate::file::parser::parse_webx_file;
use crate::file::webx::WebXFile;
use crate::file::webx::WXFile;
use crate::project::{
construct_dependency_tree, detect_circular_dependencies, load_project_config, locate_webx_files,
};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn run(root: &Path, prod: bool) {
"Webx modules: {:?}",
webx_modules
.iter()
.map(WebXFile::module_name)
.map(WXFile::module_name)
.collect::<Vec<_>>()
.join(", ")
);
Expand Down
59 changes: 36 additions & 23 deletions src/file/webx.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
use std::path::PathBuf;

pub type WXType = String;

pub type WXTypedIdentifier = (String, WXType);

#[derive(Debug)]
pub enum WXUrlPathSegment {
Literal(String),
Parameter(WXTypedIdentifier),
Regex(String),
}

pub type WXUrlPath = Vec<WXUrlPathSegment>;
pub const WXRootPath: WXUrlPath = WXUrlPath::new();

/// # WebX file format
/// A module for working with WebX files.
#[derive(Debug)]
pub struct WebXFile {
pub struct WXFile {
/// The path to the file.
pub path: PathBuf,
/// Global webx module scope.
pub module_scope: WebXScope,
pub module_scope: WXScope,
}

impl WebXFile {
impl WXFile {
/// "/path/to/file.webx" -> "path/to"
pub fn parent(&self) -> String {
let cwd = std::env::current_dir().unwrap().canonicalize().unwrap();
Expand Down Expand Up @@ -47,44 +61,43 @@ impl WebXFile {
}

#[derive(Debug)]
pub struct WebXScope {
pub struct WXScope {
pub path: WXUrlPath,
/// The dependencies of the scope.
pub includes: Vec<String>,
/// Global TypeScript code block
pub global_ts: String,
/// ORM Model definitions
pub models: Vec<WebXModel>,
pub models: Vec<WXModel>,
/// Handler functions
pub handlers: Vec<WebXHandler>,
pub handlers: Vec<WXHandler>,
/// Route endpoints
pub routes: Vec<WebXRoute>,
pub routes: Vec<WXRoute>,
/// Nested scopes.
/// Created by root and the `location` keyword.
pub scopes: Vec<WebXScope>,
pub scopes: Vec<WXScope>,
}

pub type TypedIdentifier = (String, String);

#[derive(Debug)]
pub struct WebXModel {
pub struct WXModel {
/// The name of the model.
pub name: String,
/// The fields of the model.
pub fields: Vec<TypedIdentifier>,
pub fields: Vec<WXTypedIdentifier>,
}

#[derive(Debug)]
pub struct WebXHandler {
pub struct WXHandler {
/// The name of the handler.
pub name: String,
/// The parameters of the handler.
pub params: Vec<TypedIdentifier>,
pub params: Vec<WXTypedIdentifier>,
/// The typescript body of the handler.
pub body: WebXBody,
pub body: WXBody,
}

#[derive(Debug)]
pub enum WebXRouteMethod {
pub enum WXRouteMethod {
CONNECT,
DELETE,
GET,
Expand All @@ -97,31 +110,31 @@ pub enum WebXRouteMethod {
}

#[derive(Debug)]
pub enum WebXBodyType {
pub enum WXBodyType {
TS,
TSX,
JSON,
TEXT,
}

#[derive(Debug)]
pub struct WebXBody {
pub body_type: WebXBodyType,
pub struct WXBody {
pub body_type: WXBodyType,
pub body: String,
}

#[derive(Debug)]
pub struct WebXRoute {
pub struct WXRoute {
/// HTTP method of the route.
pub method: WebXRouteMethod,
pub method: WXRouteMethod,
/// The path of the route.
pub path: String,
pub path: WXUrlPath,
/// Request body format.
pub body_format: Option<String>,
/// The pre-handler functions of the route.
pub pre_handlers: Vec<String>,
/// The code block of the route.
pub body: Option<WebXBody>,
pub body: Option<WXBody>,
/// The post-handler functions of the route.
pub post_handlers: Vec<String>,
}
4 changes: 2 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use crate::{
file::webx::WebXFile,
file::webx::WXFile,
reporting::{
error::{exit_error, ERROR_CIRCULAR_DEPENDENCY},
warning::warning,
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn detect_circular_dependencies(tree: &DependencyTree) -> Vec<PathBuf> {
///
/// ## Returns
/// The dependency tree.
pub fn construct_dependency_tree(files: &Vec<WebXFile>) -> DependencyTree {
pub fn construct_dependency_tree(files: &Vec<WXFile>) -> DependencyTree {
let mut tree = DependencyTree::new();
for file in files.iter() {
// Insert dependencies into the tree as keys and the file path as the value.
Expand Down

0 comments on commit c0ebbb6

Please sign in to comment.