#![cfg(feature = "rt_worker")]
pub use ::ohkami_macros::{DurableObject, bindings, worker};
pub trait FromEnv: Sized {
fn from_env(env: &worker::Env) -> Result<Self, worker::Error>;
#[doc(hidden)]
fn bindings_meta() -> &'static [(&'static str, Option<&'static str>)] {
&[]
}
#[doc(hidden)]
fn dummy_env() -> worker::Env {
use worker::js_sys::{Function, Object, Reflect};
use worker::wasm_bindgen::{JsCast, closure::Closure};
let env = Object::new();
for (binding_name, binding_type) in Self::bindings_meta() {
let binding = Object::new();
if let Some(binding_type) = binding_type {
let constructor = Function::<fn() -> worker::js_sys::Undefined>::unchecked_from_js(
Closure::<dyn Fn()>::new(|| {}).into_js_value(),
);
{
let attributes = Object::new();
Reflect::set(&attributes, &"value".into(), &(*binding_type).into()).unwrap();
Reflect::define_property(&constructor, &"name".into(), &attributes).unwrap();
}
Reflect::set(&binding, &"constructor".into(), &constructor).unwrap();
}
Reflect::set(&env, &(*binding_name).into(), &binding).unwrap();
}
worker::Env::unchecked_from_js(env.unchecked_into())
}
}
pub mod bindings {
pub type Var = &'static str;
pub type Secret = String;
pub type AI = ::worker::Ai;
pub type KV = ::worker::kv::KvStore;
pub type R2 = ::worker::Bucket;
pub type Service = ::worker::Fetcher;
pub type DurableObject = ::worker::ObjectNamespace;
pub type D1 = ::worker::d1::D1Database;
pub type Hyperdrive = ::worker::Hyperdrive;
pub type Queue = ::worker::Queue;
pub type AnalyticsEngine = ::worker::AnalyticsEngineDataset;
pub type DynamicDispatcher = ::worker::DynamicDispatcher;
pub type Assets = ::worker::Fetcher;
pub type SecretStore = ::worker::SecretStore;
pub type RateLimiter = ::worker::RateLimiter;
}
#[doc(hidden)]
#[allow(non_camel_case_types)]
pub trait has_DurableObject_attribute {}
#[allow(async_fn_in_trait/* `Send` is not needed */)]
pub trait DurableObject: has_DurableObject_attribute {
fn new(state: worker::State, env: worker::Env) -> Self;
async fn fetch(&mut self, req: worker::Request) -> worker::Result<worker::Response>;
async fn alarm(&mut self) -> worker::Result<worker::Response> {
worker::console_error!("alarm() handler is not implemented");
Err(worker::Error::RustError(
"alarm() handler is not implemented".into(),
))
}
#[allow(unused_variables)]
async fn websocket_message(
&mut self,
ws: worker::WebSocket,
message: worker::WebSocketIncomingMessage,
) -> worker::Result<()> {
Ok(())
}
#[allow(unused_variables)]
async fn websocket_close(
&mut self,
ws: worker::WebSocket,
code: usize,
reason: String,
was_clean: bool,
) -> worker::Result<()> {
Ok(())
}
#[allow(unused_variables)]
async fn websocket_error(
&mut self,
ws: worker::WebSocket,
error: worker::Error,
) -> worker::Result<()> {
Ok(())
}
}