#[cfg(feature = "ic-agent")]
#[cfg_attr(docsrs, doc(cfg(feature = "ic-agent")))]
mod agent;
mod ic;
#[cfg(feature = "pocket-ic")]
#[cfg_attr(docsrs, doc(cfg(feature = "pocket-ic")))]
mod pocket_ic;
mod types;
use candid::{CandidType, Principal};
use ic_dbms_api::prelude::{
AggregateFunction, AggregatedRow, DeleteBehavior, Filter, IcDbmsResult, IdentityPerms,
InsertRecord, JoinColumnDef, MigrationOp, MigrationPolicy, Query, TablePerms, TableSchema,
TransactionId, UpdateRecord, Value,
};
#[cfg(feature = "ic-agent")]
#[cfg_attr(docsrs, doc(cfg(feature = "ic-agent")))]
pub use self::agent::IcDbmsAgentClient;
pub use self::ic::IcDbmsCanisterClient;
#[cfg(feature = "pocket-ic")]
#[cfg_attr(docsrs, doc(cfg(feature = "pocket-ic")))]
pub use self::pocket_ic::IcDbmsPocketIcClient;
use crate::prelude::IcDbmsCanisterClientResult;
type RawRecords = Vec<Vec<(JoinColumnDef, Value)>>;
pub trait Client {
fn principal(&self) -> Principal;
fn grant_admin(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn revoke_admin(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn grant_manage_acl(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn revoke_manage_acl(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn grant_migrate(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn revoke_migrate(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn grant_all_tables_perms(
&self,
principal: Principal,
perms: TablePerms,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn revoke_all_tables_perms(
&self,
principal: Principal,
perms: TablePerms,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn grant_table_perms(
&self,
principal: Principal,
table: &str,
perms: TablePerms,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn revoke_table_perms(
&self,
principal: Principal,
table: &str,
perms: TablePerms,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn remove_identity(
&self,
principal: Principal,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn list_identities(
&self,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<Vec<(Principal, IdentityPerms)>>>>;
fn my_perms(&self) -> impl Future<Output = IcDbmsCanisterClientResult<IdentityPerms>>;
fn begin_transaction(&self) -> impl Future<Output = IcDbmsCanisterClientResult<TransactionId>>;
fn commit(
&self,
transaction_id: TransactionId,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn rollback(
&self,
transaction_id: TransactionId,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
fn select<T>(
&self,
table: &str,
query: Query,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<Vec<T::Record>>>>
where
T: TableSchema,
T::Record: CandidType + for<'de> candid::Deserialize<'de>;
fn aggregate<T>(
&self,
table: &str,
query: Query,
aggregates: Vec<AggregateFunction>,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<Vec<AggregatedRow>>>>
where
T: TableSchema;
fn select_raw(
&self,
table: &str,
query: Query,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<RawRecords>>>;
fn insert<T>(
&self,
table: &str,
record: T::Insert,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>
where
T: TableSchema,
T::Insert: InsertRecord<Schema = T> + CandidType;
fn update<T>(
&self,
table: &str,
patch: T::Update,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<u64>>>
where
T: TableSchema,
T::Update: UpdateRecord<Schema = T> + CandidType;
fn delete<T>(
&self,
table: &str,
behaviour: DeleteBehavior,
filter: Option<Filter>,
transaction_id: Option<TransactionId>,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<u64>>>
where
T: TableSchema;
fn has_drift(&self) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<bool>>>;
fn pending_migrations(
&self,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<Vec<MigrationOp>>>>;
fn migrate(
&self,
policy: MigrationPolicy,
) -> impl Future<Output = IcDbmsCanisterClientResult<IcDbmsResult<()>>>;
}