#![allow(non_snake_case)]
use anyhow::Result;
use client::{AuraeConfig, Client};
use deno_core::{self, op2, OpState, Resource, ResourceId};
use std::{cell::RefCell, rc::Rc};
#[op2(fast)]
#[smi]
pub(crate) fn as__aurae_config__try_default(
op_state: &mut OpState,
) -> Result<ResourceId> {
let config = AuraeConfig::try_default()?;
let rid = op_state.resource_table.add(AuraeScriptConfig(config));
Ok(rid)
}
#[op2(fast)]
#[smi]
pub(crate) fn as__aurae_config__from_options(
op_state: &mut OpState,
#[string] ca_crt: String,
#[string] client_crt: String,
#[string] client_key: String,
#[string] socket: String,
) -> ResourceId {
let config =
AuraeConfig::from_options(ca_crt, client_crt, client_key, socket);
op_state.resource_table.add(AuraeScriptConfig(config))
}
#[op2(fast)]
#[smi]
pub(crate) fn as__aurae_config__parse_from_file(
op_state: &mut OpState,
#[string] path: String,
) -> Result<ResourceId> {
let config = AuraeConfig::parse_from_toml_file(path)?;
let rid = op_state.resource_table.add(AuraeScriptConfig(config));
Ok(rid)
}
pub(crate) struct AuraeScriptConfig(pub AuraeConfig);
impl Resource for AuraeScriptConfig {} #[op2(async)]
#[smi]
pub(crate) async fn as__client_new(
op_state: Rc<RefCell<OpState>>,
#[smi] config: ResourceId,
) -> Result<ResourceId> {
let config = {
let op_state = &op_state.borrow();
let rt = &op_state.resource_table; rt.get::<AuraeScriptConfig>(config)?.0.clone() };
let client = Client::new(config).await?;
let mut op_state = op_state.borrow_mut();
let rid = op_state.resource_table.add(AuraeScriptClient(client));
Ok(rid)
}
pub(crate) fn op_decls() -> Vec<::deno_core::OpDecl> {
vec![
as__aurae_config__try_default(),
as__aurae_config__from_options(),
as__aurae_config__parse_from_file(),
as__client_new(),
]
}
pub(crate) struct AuraeScriptClient(pub Client);
impl Resource for AuraeScriptClient {}