chore: removed prelude imports and fixed glue exports

This commit is contained in:
frelodev 2024-08-14 18:00:12 +02:00
parent b46914528a
commit 2d20887509
5 changed files with 27 additions and 22 deletions

View file

@ -1,4 +1,7 @@
{ {
"name": "@codemp/codemp",
"version": "0.0.1",
"dependencies": { "dependencies": {
"@napi-rs/cli": "^2.18.0", "@napi-rs/cli": "^2.18.0",
"npx": "^10.2.2" "npx": "^10.2.2"

View file

@ -2,11 +2,12 @@ use napi::threadsafe_function::{ErrorStrategy::Fatal, ThreadSafeCallContext, Thr
use napi_derive::napi; use napi_derive::napi;
use crate::api::TextChange; use crate::api::TextChange;
use crate::api::Controller; use crate::api::Controller;
use crate::prelude::*; use crate::buffer::controller::BufferController;
#[napi] #[napi]
impl CodempBufferController { impl BufferController {
#[napi(ts_args_type = "fun: (event: JsTextChange) => void")] #[napi(ts_args_type = "fun: (event: TextChange) => void")]
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{ pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> = let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> =
fun.create_threadsafe_function(0, fun.create_threadsafe_function(0,

View file

@ -1,9 +1,9 @@
use napi_derive::napi; use napi_derive::napi;
use crate::prelude::*; use crate::{Client, Workspace};
#[napi] #[napi]
/// connect to codemp servers and return a client session /// connect to codemp servers and return a client session
pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<CodempClient>{ pub async fn connect(addr: Option<String>, username: String, password: String) -> napi::Result<crate::Client>{
let client = crate::Client::new(addr.as_deref().unwrap_or("http://codemp.alemi.dev:50053"), username, password) let client = crate::Client::new(addr.as_deref().unwrap_or("http://codemp.alemi.dev:50053"), username, password)
.await?; .await?;
@ -11,16 +11,16 @@ pub async fn connect(addr: Option<String>, username: String, password: String) -
} }
#[napi] #[napi]
impl CodempClient { impl Client {
#[napi(js_name = "join_workspace")] #[napi(js_name = "join_workspace")]
/// join workspace with given id (will start its cursor controller) /// join workspace with given id (will start its cursor controller)
pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<CodempWorkspace> { pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<Workspace> {
Ok(self.join_workspace(workspace).await?) Ok(self.join_workspace(workspace).await?)
} }
#[napi(js_name = "get_workspace")] #[napi(js_name = "get_workspace")]
/// get workspace with given id, if it exists /// get workspace with given id, if it exists
pub fn js_get_workspace(&self, workspace: String) -> Option<CodempWorkspace> { pub fn js_get_workspace(&self, workspace: String) -> Option<Workspace> {
self.get_workspace(&workspace) self.get_workspace(&workspace)
} }
@ -31,6 +31,7 @@ impl CodempClient {
} }
#[napi(js_name = "active_workspaces")] #[napi(js_name = "active_workspaces")]
/// get list of all active workspaces
pub fn js_active_workspaces(&self) -> Vec<String> { pub fn js_active_workspaces(&self) -> Vec<String> {
self.active_workspaces() self.active_workspaces()
} }

View file

@ -1,7 +1,7 @@
use napi_derive::napi; use napi_derive::napi;
use napi::threadsafe_function::{ThreadsafeFunction, ThreadSafeCallContext, ThreadsafeFunctionCallMode, ErrorStrategy}; use napi::threadsafe_function::{ThreadsafeFunction, ThreadSafeCallContext, ThreadsafeFunctionCallMode, ErrorStrategy};
use crate::api::Controller; use crate::api::Controller;
use crate::prelude::*; use crate::cursor::controller::CursorController;
#[napi(object, js_name = "Cursor")] #[napi(object, js_name = "Cursor")]
@ -15,9 +15,9 @@ pub struct JsCursor {
pub user: Option<String>, pub user: Option<String>,
} }
impl From<JsCursor> for CodempCursor { impl From<JsCursor> for crate::api::Cursor {
fn from(value: JsCursor) -> Self { fn from(value: JsCursor) -> Self {
CodempCursor { crate::api::Cursor {
start : (value.start_row, value.start_col), start : (value.start_row, value.start_col),
end: (value.end_row, value.end_col), end: (value.end_row, value.end_col),
buffer: value.buffer, buffer: value.buffer,
@ -25,8 +25,8 @@ impl From<JsCursor> for CodempCursor {
} }
} }
} }
impl From<CodempCursor> for JsCursor { impl From<crate::api::Cursor> for JsCursor {
fn from(value: CodempCursor) -> Self { fn from(value: crate::api::Cursor) -> Self {
JsCursor { JsCursor {
start_row : value.start.0, start_row : value.start.0,
start_col : value.start.1, start_col : value.start.1,
@ -41,8 +41,8 @@ impl From<CodempCursor> for JsCursor {
#[napi] #[napi]
impl CodempCursorController { impl CursorController {
#[napi(ts_args_type = "fun: (event: JsCursorEvent) => void")] #[napi(ts_args_type = "fun: (event: Cursor) => void")]
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{ pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> = let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> =
fun.create_threadsafe_function(0, fun.create_threadsafe_function(0,

View file

@ -1,11 +1,11 @@
use std::sync::Arc;
use napi_derive::napi; use napi_derive::napi;
use crate::prelude::*; use crate::Workspace;
use crate::buffer::controller::BufferController;
use crate::cursor::controller::CursorController;
#[napi] #[napi]
impl CodempWorkspace { impl Workspace {
#[napi(js_name = "id")] #[napi(js_name = "id")]
pub fn js_id(&self) -> String { pub fn js_id(&self) -> String {
self.id() self.id()
@ -17,12 +17,12 @@ impl CodempWorkspace {
} }
#[napi(js_name = "cursor")] #[napi(js_name = "cursor")]
pub fn js_cursor(&self) -> CodempCursorController { pub fn js_cursor(&self) -> CursorController {
self.cursor() self.cursor()
} }
#[napi(js_name = "buffer_by_name")] #[napi(js_name = "buffer_by_name")]
pub fn js_buffer_by_name(&self, path: String) -> Option<CodempBufferController> { pub fn js_buffer_by_name(&self, path: String) -> Option<BufferController> {
self.buffer_by_name(&path) self.buffer_by_name(&path)
} }
@ -32,7 +32,7 @@ impl CodempWorkspace {
} }
#[napi(js_name = "attach")] #[napi(js_name = "attach")]
pub async fn js_attach(&self, path: String) -> napi::Result<CodempBufferController> { pub async fn js_attach(&self, path: String) -> napi::Result<BufferController> {
Ok(self.attach(&path).await?) Ok(self.attach(&path).await?)
} }