askexperts
Version:
AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol
175 lines • 6.48 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _DBClient_user_id;
import { getDB } from "./utils.js";
import { getCurrentUserId } from "../common/users.js";
/**
* Client implementation of the DBInterface
* Passes all calls to the DB instance except getUserId()
*/
export class DBClient {
/**
* Creates a new DBClient instance
*/
constructor() {
_DBClient_user_id.set(this, void 0);
this.db = getDB();
}
user_id() {
if (!__classPrivateFieldGet(this, _DBClient_user_id, "f"))
__classPrivateFieldSet(this, _DBClient_user_id, getCurrentUserId(), "f");
return __classPrivateFieldGet(this, _DBClient_user_id, "f");
}
/**
* List all wallets
* @returns Promise resolving to an array of wallet objects
*/
async listWallets() {
return this.db.listWallets(this.user_id());
}
/**
* 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
*/
async listWalletsByIds(ids) {
return this.db.listWalletsByIds(ids);
}
/**
* Get a wallet by ID
* @param id - ID of the wallet to get
* @returns Promise resolving to the wallet if found, null otherwise
*/
async getWallet(id) {
return this.db.getWallet(id, this.user_id());
}
/**
* Get a wallet by name
* @param name - Name of the wallet to get
* @returns Promise resolving to the wallet if found, null otherwise
*/
async getWalletByName(name) {
return this.db.getWalletByName(name, this.user_id());
}
/**
* Get the default wallet
* @returns Promise resolving to the default wallet if found, null otherwise
*/
async getDefaultWallet() {
return this.db.getDefaultWallet(this.user_id());
}
/**
* Insert a new wallet
* @param wallet - Wallet to insert (without id)
* @returns Promise resolving to the ID of the inserted wallet
*/
async insertWallet(wallet) {
return this.db.insertWallet(wallet);
}
/**
* Update an existing wallet
* @param wallet - Wallet to update
* @returns Promise resolving to true if wallet was updated, false otherwise
*/
async updateWallet(wallet) {
return this.db.updateWallet(wallet);
}
/**
* Delete a wallet
* @param id - ID of the wallet to delete
* @returns Promise resolving to true if wallet was deleted, false otherwise
*/
async deleteWallet(id) {
return this.db.deleteWallet(id, this.user_id());
}
/**
* List all experts
* @returns Promise resolving to an array of expert objects
*/
async listExperts() {
return this.db.listExperts(this.user_id());
}
/**
* 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
*/
async listExpertsByIds(ids) {
return this.db.listExpertsByIds(ids);
}
/**
* 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)
* @returns Promise resolving to an array of expert objects
*/
async listExpertsAfter(timestamp, limit = 1000) {
return this.db.listExpertsAfter(timestamp, limit, this.user_id());
}
/**
* Get an expert by pubkey
* @param pubkey - Pubkey of the expert to get
* @returns Promise resolving to the expert if found, null otherwise
*/
async getExpert(pubkey) {
return this.db.getExpert(pubkey, this.user_id());
}
/**
* Insert a new expert
* @param expert - Expert to insert
* @returns Promise resolving to true if expert was inserted, false otherwise
*/
async insertExpert(expert) {
return this.db.insertExpert(expert);
}
/**
* Update an existing expert
* @param expert - Expert to update
* @returns Promise resolving to true if expert was updated, false otherwise
*/
async updateExpert(expert) {
return this.db.updateExpert(expert);
}
/**
* Set the disabled status of an expert
* @param pubkey - Pubkey of the expert to update
* @param disabled - Whether the expert should be disabled
* @returns Promise resolving to true if expert was updated, false otherwise
*/
async setExpertDisabled(pubkey, disabled) {
return this.db.setExpertDisabled(pubkey, disabled, this.user_id());
}
/**
* Delete an expert
* @param pubkey - Pubkey of the expert to delete
* @returns Promise resolving to true if expert was deleted, false otherwise
*/
async deleteExpert(pubkey) {
return this.db.deleteExpert(pubkey, this.user_id());
}
/**
* Get the current user ID
* @returns Promise resolving to the current user ID
*/
async getUserId() {
return this.user_id();
}
/**
* Symbol.dispose method for releasing resources
*/
[(_DBClient_user_id = new WeakMap(), Symbol.dispose)]() {
if (this.db && typeof this.db[Symbol.dispose] === 'function') {
this.db[Symbol.dispose]();
}
}
}
//# sourceMappingURL=DBClient.js.map