askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
167 lines (166 loc) • 6.26 kB
TypeScript
import { DBWallet, DBExpert, DBUser } from "./interfaces.js";
/**
* SQLite implementation of the database for experts, wallets, and docstore servers
*/
export declare class DB {
private db;
/**
* Creates a new DB instance
* @param dbPath - Path to the SQLite database file
*/
constructor(dbPath: string);
/**
* Initialize the database by creating required tables if they don't exist
*/
private initDatabase;
/**
* List all wallets
* @param user_id - Optional user ID to filter wallets by
* @returns Array of wallet objects
*/
listWallets(user_id?: string): Promise<DBWallet[]>;
/**
* List wallets by specific IDs
* @param ids - Array of wallet IDs to retrieve
* @returns Promise resolving to an array of wallet objects matching the provided IDs
*/
listWalletsByIds(ids: string[]): Promise<DBWallet[]>;
/**
* Get a wallet by ID
* @param id - ID of the wallet to get
* @param user_id - Optional user ID to filter by
* @returns The wallet if found, null otherwise
*/
getWallet(id: string, user_id?: string): Promise<DBWallet | null>;
/**
* Get a wallet by name
* @param name - Name of the wallet to get
* @param user_id - Optional user ID to filter by
* @returns The wallet if found, null otherwise
*/
getWalletByName(name: string, user_id?: string): Promise<DBWallet | null>;
/**
* Get the default wallet
* @param user_id - Optional user ID to filter by
* @returns The default wallet if found, null otherwise
*/
getDefaultWallet(user_id?: string): Promise<DBWallet | null>;
/**
* Insert a new wallet
* @param wallet - Wallet to insert (without id)
* @returns ID of the inserted wallet
*/
insertWallet(wallet: Omit<DBWallet, "id">): Promise<string>;
/**
* Update an existing wallet
* @param wallet - Wallet to update
* @returns true if wallet was updated, false otherwise
*/
updateWallet(wallet: DBWallet): Promise<boolean>;
/**
* Delete a wallet
* @param id - ID of the wallet to delete
* @param user_id - Optional user ID to filter by
* @returns true if wallet was deleted, false otherwise
*/
deleteWallet(id: string, user_id?: string): Promise<boolean>;
/**
* List all experts
* @param user_id - Optional user ID to filter experts by
* @returns Promise resolving to an array of expert objects
*/
listExperts(user_id?: string): Promise<DBExpert[]>;
/**
* List experts with timestamp newer than the provided timestamp
* @param timestamp - Only return experts with timestamp newer than this
* @param limit - Maximum number of experts to return (default: 1000)
* @param user_id - Optional user ID to filter experts by
* @returns Promise resolving to an array of expert objects
*/
listExpertsAfter(timestamp: number, limit?: number, user_id?: string): Promise<DBExpert[]>;
/**
* List experts by specific IDs
* @param ids - Array of expert pubkeys to retrieve
* @returns Promise resolving to an array of expert objects matching the provided IDs
*/
listExpertsByIds(ids: string[]): Promise<DBExpert[]>;
/**
* Get an expert by pubkey
* @param pubkey - Pubkey of the expert to get
* @param user_id - Optional user ID to filter by
* @returns Promise resolving to the expert if found, null otherwise
*/
getExpert(pubkey: string, user_id?: string): Promise<DBExpert | null>;
/**
* Insert a new expert
* @param expert - Expert to insert
* @returns Promise resolving to true if expert was inserted, false otherwise
*/
insertExpert(expert: DBExpert): Promise<boolean>;
/**
* Update an existing expert
* @param expert - Expert to update
* @returns Promise resolving to true if expert was updated, false otherwise
*/
updateExpert(expert: DBExpert): Promise<boolean>;
/**
* Set the disabled status of an expert
* @param pubkey - Pubkey of the expert to update
* @param disabled - Whether the expert should be disabled
* @param user_id - Optional user ID to filter by
* @returns Promise resolving to true if expert was updated, false otherwise
*/
setExpertDisabled(pubkey: string, disabled: boolean, user_id?: string): Promise<boolean>;
/**
* Delete an expert
* @param pubkey - Pubkey of the expert to delete
* @param user_id - Optional user ID to filter by
* @returns Promise resolving to true if expert was deleted, false otherwise
*/
deleteExpert(pubkey: string, user_id?: string): Promise<boolean>;
/**
* List all users
* @returns Promise resolving to an array of user objects
*/
listUsers(): Promise<DBUser[]>;
/**
* Get a user by ID
* @param id - ID of the user to get
* @returns Promise resolving to the user if found, null otherwise
*/
getUser(id: string): Promise<DBUser | null>;
/**
* Get a user by pubkey
* @param pubkey - Pubkey of the user to get
* @returns Promise resolving to the user if found, null otherwise
*/
getUserByPubkey(pubkey: string): Promise<DBUser | null>;
/**
* Get a user by external ID
* @param user_id_ext - External ID of the user to get
* @returns Promise resolving to the user if found, null otherwise
*/
getUserByExtId(user_id_ext: string): Promise<DBUser | null>;
/**
* Insert a new user
* @param user - User to insert (without id)
* @returns Promise resolving to the ID of the inserted user
*/
insertUser(user: Omit<DBUser, "id">): Promise<string>;
/**
* Update an existing user
* @param user - User to update
* @returns Promise resolving to true if user was updated, false otherwise
*/
updateUser(user: DBUser): Promise<boolean>;
/**
* Delete a user
* @param id - ID of the user to delete
* @returns Promise resolving to true if user was deleted, false otherwise
*/
deleteUser(id: string): Promise<boolean>;
/**
* Symbol.dispose method for releasing resources
*/
[Symbol.dispose](): void;
}