mod application;
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
mod http1;
mod programming;
mod startup_candidate;
pub use application::ProductionLauncher;
pub use application::SaddleConfig;
pub use application::{
ApprovedBundleNonceReservation, ApprovedExternalBundle,
ApprovedExternalBundleApplicabilityFailure, ApprovedExternalBundleSeal,
ApprovedExternalBundleVerification, ListenerAuthorityProvider, ListenerAuthoritySeal,
VerifiedListenerAuthority,
};
#[doc(hidden)]
pub use application::{
GeneratedApplicationBindingError, GeneratedApplicationConsumer, GeneratedApplicationOwner,
GeneratedApplicationParts, GeneratedApplicationSeal, GeneratedBoundApplicationParts,
GeneratedProductionBootstrap,
};
#[doc(hidden)]
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
pub mod internal {
pub use crate::http1::bootstrap::{
ApprovedGeneratedHttp1Facts, GeneratedApplicationBootstrap, GeneratedBootstrapError,
GeneratedBootstrapToken, GeneratedCompiledAdapter, GeneratedContextFactory,
GeneratedHttp1StaticFacts, GeneratedRoute, generated_bootstrap_type_identity,
generated_http1_framing_identity,
};
}
pub use saddle_core::{ErrorKind, Result, SaddleError};
#[doc(hidden)]
pub mod __private {
pub use crate::programming::{
ProfuseContractDeployment, ProfuseGwDispatchError, decode_accepted_profusegw,
ingress_matches_contract,
};
pub use saddle_boundary::ProfuseContractEndpoint;
pub use saddle_boundary::ingress::{AcceptedIngress, ProfuseGwListenerAdapter};
pub use saddle_macros::contract_dir;
}
pub mod ingress {
pub use crate::programming::{
MAX_PROFUSE_GW_USER_ID_BYTES, ProfuseGwContext, ProfuseGwDispatchError,
};
}
pub mod profusecontract {
#[doc(hidden)]
pub use crate::programming::ApplicationContractSeal;
pub use crate::programming::{
DeclaredExternalFunctionCall, ExecutionCertainty, ExternalFunctionResult, TechnicalFailure,
TechnicalFailureCode,
};
pub mod testing {
pub use crate::programming::{
FakeApplicationBinding, FakeAttempt, FakeExecutionCertainty,
FakeProfuseContractBoundary, FakeStep, FakeTechnicalCode,
};
}
}
pub mod managed {
pub use saddle_db::internal::ManagedWriteResult as WriteResult;
pub use saddle_service::internal::{
ManagedBool as Bool, ManagedPair as Pair, ManagedU64 as U64,
};
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Optional<T>(Option<T>);
impl<T> Optional<T> {
#[doc(hidden)]
pub const fn from_generated(value: Option<T>) -> Self {
Self(value)
}
pub fn into_option(self) -> Option<T> {
self.0
}
pub const fn as_ref(&self) -> Option<&T> {
self.0.as_ref()
}
}
}
#[macro_export]
macro_rules! application {
(
schema "saddle-application/1";
application $application:ident;
$($declaration:tt)*
) => {
pub struct $application;
};
(
schema "saddle-application/2";
application $application:ident;
deployment_app $deployment_app:literal;
profusecontract {
contract_dir $contract_dir:literal;
capability $capability:ident;
functions {
$(
$function:ident => $method:ident {
business_unit $business_unit:literal;
function $function_name:literal;
} (
$function_request:ty
) -> $function_result:ty;
)+
}
}
$(
service $service:ident {
ingress profusegw;
operation_type $operation_type:literal;
request $request:ty;
response $response:ty;
handler $handler:path;
$(uses $uses:ident;)+
}
)+
) => {
const __SADDLE_ONLY_APPLICATION: () = ();
$crate::__private::contract_dir!(
$contract_dir;
declarations {
$(($function, $business_unit, $function_name, $function_request, $function_result);)+
}
uses {
$($($uses;)+)+
}
);
pub struct $application;
trait __SaddleDeclaredExternalFunction {}
$(
pub struct $function;
impl __SaddleDeclaredExternalFunction for $function {}
)+
pub struct $capability {
__seal: $crate::profusecontract::ApplicationContractSeal,
}
impl $capability {
#[doc(hidden)]
pub fn __from_framework(
seal: $crate::profusecontract::ApplicationContractSeal,
) -> Self {
Self { __seal: seal }
}
$(
pub fn $method(
&self,
request: $function_request,
) -> $crate::profusecontract::DeclaredExternalFunctionCall<
$application,
$function,
$function_request,
$function_result,
> {
$crate::profusecontract::DeclaredExternalFunctionCall::from_declared(
request,
&self.__seal,
$business_unit,
$function_name,
)
}
)+
}
impl $application {
pub const PROFUSECONTRACT_DIR: &'static str = $contract_dir;
#[doc(hidden)]
pub const __PROFUSECONTRACT_DESCRIPTOR: &'static [u8] =
__SADDLE_CONTRACT_DESCRIPTOR;
pub fn dispatch_profusegw_operation(
operation_type: &str,
) -> Option<ProfuseGwDispatch> {
match operation_type {
$(
$operation_type => Some(ProfuseGwDispatch::$service),
)+
_ => None,
}
}
#[doc(hidden)]
pub fn __profusegw_listener_adapter(
) -> $crate::__private::ProfuseGwListenerAdapter {
$crate::__private::ProfuseGwListenerAdapter::new($deployment_app)
.expect("generated deployment application identity is valid")
}
#[doc(hidden)]
pub async fn __connect_profusecontract(
endpoint: $crate::__private::ProfuseContractEndpoint,
) -> ::core::result::Result<
$crate::__private::ProfuseContractDeployment,
$crate::profusecontract::TechnicalFailure,
> {
$crate::__private::ProfuseContractDeployment::connect(endpoint).await
}
#[doc(hidden)]
pub fn __bind_profusecontract(
deployment: &$crate::__private::ProfuseContractDeployment,
accepted: &$crate::__private::AcceptedIngress,
) -> $capability {
$capability::__from_framework(deployment.bind_accepted(accepted))
}
#[doc(hidden)]
pub async fn __dispatch_accepted_profusegw(
accepted: $crate::__private::AcceptedIngress,
contract: $capability,
) -> ::core::result::Result<ProfuseGwResponse, $crate::__private::ProfuseGwDispatchError> {
if !$crate::__private::ingress_matches_contract(&accepted, &contract.__seal) {
return Err($crate::__private::ProfuseGwDispatchError::IdentityMismatch);
}
match accepted.interface_id.as_str() {
$(
$operation_type => {
let (request, context) =
$crate::__private::decode_accepted_profusegw::<$request>(accepted)?;
Ok(ProfuseGwResponse::$service(
$handler(request, context, contract).await,
))
}
)+
_ => Err($crate::__private::ProfuseGwDispatchError::InterfaceNotFound),
}
}
}
pub enum ProfuseGwResponse {
$($service($response)),+
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ProfuseGwDispatch {
$($service),+
}
$(
pub struct $service;
impl $service {
pub const OPERATION_TYPE: &'static str = $operation_type;
}
const _: fn() = || {
fn handler_shape<F, Fut>(_: F)
where
F: Fn($request, $crate::ingress::ProfuseGwContext, $capability) -> Fut,
Fut: ::core::future::Future<Output = $response>,
{}
handler_shape($handler);
fn declared_use<F>()
where
F: __SaddleDeclaredExternalFunction,
{}
$(declared_use::<$uses>();)+
};
)+
};
($($invalid:tt)*) => {
compile_error!("skill.schema.unsupported");
};
}