Skip to content

Commit

Permalink
0.2.21
Browse files Browse the repository at this point in the history
  • Loading branch information
victorteokw committed Mar 22, 2024
1 parent 0aa6def commit 9302e52
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
edition = "2021"
name = "teocloud_teo"
version = "0.2.20"
version = "0.2.21"

[lib]
crate-type = ["cdylib"]

[dependencies]
teo = { version = "0.2.20" }
teo-result = { version = "0.2.20", features = ["napi"] }
teo = { version = "0.2.21" }
teo-result = { version = "0.2.21", features = ["napi"] }
napi = { version = "2.16.0", default-features = false, features = ["napi5", "async", "chrono_date", "compat-mode"] }
napi-derive = "2.16.0"
chrono = { version = "0.4.31" }
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class App {
/** Run before server is started. */
setup(callback: (ctx: any) => void | Promise<void>): void
/** Define a custom program. */
program(name: string, callback: (ctx: any) => void | Promise<void>): void
program(name: string, desc: string | undefined, callback: (ctx: any) => void | Promise<void>): void
mainNamespace(): Namespace
}
export class ReadOnlyHeaderMap {
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ impl App {
}

/// Define a custom program.
#[napi(ts_args_type = "name: string, callback: (ctx: any) => void | Promise<void>")]
pub fn program(&self, name: String, callback: JsFunction) -> Result<()> {
#[napi(ts_args_type = "name: string, desc: string | undefined, callback: (ctx: any) => void | Promise<void>")]
pub fn program(&self, name: String, desc: Option<String>, callback: JsFunction) -> Result<()> {
let tsfn: ThreadsafeFunction<transaction::Ctx, ErrorStrategy::Fatal> = callback.create_threadsafe_function(0, |ctx: ThreadSafeCallContext<transaction::Ctx>| {
let js_ctx = js_ctx_object_from_teo_transaction_ctx(ctx.env, ctx.value.clone(), "")?;
Ok(vec![js_ctx])
})?;
let tsfn_cloned = Box::leak(Box::new(tsfn));
self.teo_app.program(name.as_str(), |ctx: transaction::Ctx| async {
self.teo_app.program(name.as_str(), desc, |ctx: transaction::Ctx| async {
let promise_or_ignore: PromiseOrIgnore = tsfn_cloned.call_async(ctx).await?;
Ok(promise_or_ignore.to_ignore().await?)
});
Expand Down
4 changes: 2 additions & 2 deletions src/object/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use object_id::ObjectId;
pub use file::File;
pub use range::Range;

use napi::{Env, JsFunction, JsUnknown, Result};
use napi::{Env, Error, JsFunction, JsUnknown, Result};
use teo::prelude::{Value as TeoValue, Value, OptionVariant as TeoOptionVariant};
use super::{interface_enum_variant::teo_interface_enum_variant_to_js_any, model::teo_model_object_to_js_any, pipeline::teo_pipeline_to_js_any, r#struct::teo_struct_object_to_js_any};

Expand Down Expand Up @@ -89,6 +89,6 @@ pub fn teo_value_to_js_any(value: &TeoValue, env: &Env) -> Result<JsUnknown> {
Value::StructObject(struct_object) => teo_struct_object_to_js_any(struct_object, env)?,
Value::Pipeline(pipeline) => teo_pipeline_to_js_any(pipeline, env)?,
Value::InterfaceEnumVariant(interface_enum_variant) => teo_interface_enum_variant_to_js_any(interface_enum_variant, env)?,

_ => Err(Error::new(napi::Status::GenericFailure, "cannot convert Teo value to Python value"))?,
})
}

0 comments on commit 9302e52

Please sign in to comment.