Skip to content

Commit

Permalink
Split into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytten committed Nov 19, 2024
1 parent c838e60 commit 715881c
Show file tree
Hide file tree
Showing 29 changed files with 157 additions and 43 deletions.
25 changes: 16 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ readme = "README.md"
default = ["all"]
all = ["timers", "url", "console", "sqlite"]

timers = ["tokio/time"]
url = []
console = []
sqlite = ["sqlx"]
timers = ["rquickjs-extra-timers"]
url = ["rquickjs-extra-url"]
console = ["rquickjs-extra-console"]
sqlite = ["rquickjs-extra-sqlite"]

[dependencies]
rquickjs-extra-console = { path = "modules/console", optional = true }
rquickjs-extra-sqlite = { path = "modules/sqlite", optional = true }
rquickjs-extra-timers = { path = "modules/timers", optional = true }
rquickjs-extra-url = { path = "modules/url", optional = true }

[workspace]
resolver = "2"
members = ["modules/*", "libs/*"]

[workspace.dependencies]
either = "1"
futures = { version = "0.3" }
log = { version = "0.4" }
rquickjs = { version = "0.6", features = [
"array-buffer",
Expand All @@ -28,9 +39,5 @@ rquickjs = { version = "0.6", features = [
sqlx = { version = "0.8.2", default-features = false, features = [
"sqlite",
"runtime-tokio",
], optional = true }
] }
tokio = { version = "1" }

[dev-dependencies]
futures = { version = "0.3" }
tokio = { version = "1", features = ["full"] }
13 changes: 13 additions & 0 deletions libs/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "rquickjs-extra-test"
description = "Test library for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
futures = { workspace = true }
rquickjs = { workspace = true }
tokio = { workspace = true, features = ["full"] }
File renamed without changes.
11 changes: 11 additions & 0 deletions libs/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rquickjs-extra-utils"
description = "Utils library for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
rquickjs = { workspace = true }
4 changes: 4 additions & 0 deletions src/ffi/c_string.rs → libs/utils/src/ffi/c_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl<'js> CString<'js> {
self.len
}

pub fn is_empty(&self) -> bool {
self.len == 0
}

pub fn as_str(&self) -> Result<&str> {
let bytes = unsafe { slice::from_raw_parts(self.ptr as *const u8, self.len) };
str::from_utf8(bytes)
Expand Down
6 changes: 5 additions & 1 deletion src/ffi/c_vec.rs → libs/utils/src/ffi/c_vec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rquickjs::{Result, TypedArray, Value};

use crate::utils::result::ResultExt;
use crate::result::ResultExt;

#[derive(Debug)]
pub struct CVec<'js> {
Expand Down Expand Up @@ -29,6 +29,10 @@ impl<'js> CVec<'js> {
self.len
}

pub fn is_empty(&self) -> bool {
self.len == 0
}

pub fn as_slice(&self) -> &[u8] {
unsafe { std::slice::from_raw_parts(self.ptr, self.len) }
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/utils/mod.rs → libs/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod ffi;
pub mod module;
pub mod result;
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions modules/console/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rquickjs-extra-console"
description = "Console module for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
log = { workspace = true }
rquickjs = { workspace = true }

[dev-dependencies]
rquickjs-extra-test = { path = "../../libs/test" }
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ impl FormatterBuilder {

#[cfg(test)]
mod tests {
use rquickjs_extra_test::test_with;

use super::*;
use crate::test::test_with;

type StdString = std::string::String;

Expand Down
3 changes: 2 additions & 1 deletion src/modules/console/mod.rs → modules/console/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ pub fn init(ctx: &Ctx<'_>) -> Result<()> {

#[cfg(test)]
mod tests {
use rquickjs_extra_test::test_with;

use super::*;
use crate::test::test_with;

#[test]
fn test_console() {
Expand Down
14 changes: 14 additions & 0 deletions modules/os/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rquickjs-extra-os"
description = "OS module for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]

[dev-dependencies]
futures = { version = "0.3" }
tokio = { version = "1", features = ["full"] }
Empty file added modules/os/src/lib.rs
Empty file.
18 changes: 18 additions & 0 deletions modules/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "rquickjs-extra-sqlite"
description = "SQLite module for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
either = { workspace = true }
rquickjs = { workspace = true }
rquickjs-extra-utils = { path = "../../libs/utils" }
sqlx = { workspace = true }

[dev-dependencies]
rquickjs-extra-test = { path = "../../libs/test" }
tokio = { workspace = true, features = ["full"] }
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use rquickjs::{Ctx, Exception, FromJs, Result, TypedArray};
use rquickjs_extra_utils::ffi::{CString, CVec};
use rquickjs_extra_utils::result::ResultExt;
use sqlx::query::Query;
use sqlx::sqlite::SqliteArguments;
use sqlx::Sqlite;

use crate::ffi::{CString, CVec};
use crate::utils::result::ResultExt;

#[derive(Debug)]
pub enum Argument<'js> {
Null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rquickjs::{Ctx, Result};
use rquickjs_extra_utils::result::ResultExt;
use sqlx::{Executor, SqlitePool};

use super::Statement;
use crate::utils::result::ResultExt;

#[rquickjs::class]
#[derive(rquickjs::class::Trace)]
Expand Down Expand Up @@ -41,9 +41,9 @@ impl Database {
#[cfg(test)]
mod tests {
use rquickjs::CatchResultExt;
use rquickjs_extra_test::{call_test, test_async_with, ModuleEvaluator};

use crate::sqlite::SqliteModule;
use crate::test::{call_test, test_async_with, ModuleEvaluator};
use crate::SqliteModule;

#[tokio::test]
async fn test_database_exec() {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/sqlite/mod.rs → modules/sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use rquickjs::{
module::{Declarations, Exports, ModuleDef},
Class, Ctx, Result,
};
use rquickjs_extra_utils::module::export_default;

pub use self::argument::Argument;
pub use self::database::Database;
pub use self::open::{open, OpenOptions};
pub use self::statement::Statement;
pub use self::value::Value;
use crate::utils::module::export_default;

mod argument;
mod database;
Expand Down
3 changes: 1 addition & 2 deletions src/modules/sqlite/open.rs → modules/sqlite/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::{

use either::Either;
use rquickjs::{Ctx, FromJs, Null, Object, Result, Value};
use rquickjs_extra_utils::result::ResultExt;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};

use crate::utils::result::ResultExt;

use super::Database;

static IN_MEMORY_DB_SEQ: AtomicUsize = AtomicUsize::new(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use rquickjs::function::Rest;
use rquickjs::{Ctx, Object, Result};
use rquickjs_extra_utils::result::ResultExt;
use sqlx::query::Query;
use sqlx::sqlite::SqliteArguments;
use sqlx::Sqlite;
use sqlx::{sqlite::SqliteStatement, Column as _, Row as _, SqlitePool, Statement as _};

use crate::utils::result::ResultExt;

use super::{Argument, Value};

#[rquickjs::class]
Expand Down Expand Up @@ -101,9 +100,9 @@ impl Statement {
#[cfg(test)]
mod tests {
use rquickjs::CatchResultExt;
use rquickjs_extra_test::{call_test, test_async_with, ModuleEvaluator};

use crate::sqlite::SqliteModule;
use crate::test::{call_test, test_async_with, ModuleEvaluator};
use crate::SqliteModule;

#[tokio::test]
async fn test_statement_all() {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/sqlite/value.rs → modules/sqlite/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use rquickjs::{Ctx, Exception, IntoJs, Result, String, TypedArray};
use rquickjs_extra_utils::result::ResultExt;
use sqlx::sqlite::{SqliteColumn, SqliteRow};
use sqlx::{Column as _, Decode, Row as _, TypeInfo as _, ValueRef};

use crate::utils::result::ResultExt;

pub enum Value<'q> {
Null,
Integer(i64),
Expand Down
18 changes: 18 additions & 0 deletions modules/timers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "rquickjs-extra-timers"
description = "Timers module for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
log = { workspace = true }
rquickjs = { workspace = true }
tokio = { workspace = true, features = ["time"] }

[dev-dependencies]
futures = { workspace = true }
rquickjs-extra-test = { path = "../../libs/test" }
tokio = { workspace = true, features = ["full"] }
2 changes: 1 addition & 1 deletion src/modules/timers.rs → modules/timers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ mod tests {
use futures::FutureExt;
use rquickjs::promise::Promise;
use rquickjs::CatchResultExt;
use rquickjs_extra_test::test_async_with;

use super::*;
use crate::test::test_async_with;

#[tokio::test]
async fn test_set_timeout() {
Expand Down
15 changes: 15 additions & 0 deletions modules/url/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rquickjs-extra-url"
description = "URL module for RQuickJS"
version = "0.0.1"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/rquickjs/rquickjs-extra"
readme = "README.md"

[dependencies]
either = { workspace = true }
rquickjs = { workspace = true }

[dev-dependencies]
rquickjs-extra-test = { path = "../../libs/test" }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ impl<'js> FromJs<'js> for URLSearchParamsInput<'js> {
#[cfg(test)]
mod tests {
use rquickjs::{CatchResultExt, Class};
use rquickjs_extra_test::test_with;

use super::*;
use crate::test::test_with;

#[test]
fn test_basic() {
Expand Down
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
pub use self::modules::*;
#[cfg(feature = "console")]
pub use rquickjs_extra_console as console;

mod ffi;
mod modules;
#[cfg(test)]
mod test;
mod utils;
#[cfg(feature = "sqlite")]
pub use rquickjs_extra_sqlite as sqlite;

#[cfg(feature = "timers")]
pub use rquickjs_extra_timers as timers;

#[cfg(feature = "url")]
pub use rquickjs_extra_url as url;
8 changes: 0 additions & 8 deletions src/modules/mod.rs

This file was deleted.

0 comments on commit 715881c

Please sign in to comment.