import { IDBPDatabase, IDBPTransaction } from 'idb'; import { ListActionsResult, ListOutputsResult, Validation } from '@bsv/sdk'; import { TableCertificate, TableCertificateField, TableCertificateX, TableCommission, TableMonitorEvent, TableOutput, TableOutputBasket, TableOutputTag, TableOutputTagMap, TableProvenTx, TableProvenTxReq, TableSettings, TableSyncState, TableTransaction, TableTxLabel, TableTxLabelMap, TableUser } from './schema/tables'; import { StorageAdminStats, StorageProvider, StorageProviderOptions } from './StorageProvider'; import { StorageIdbSchema } from './schema/StorageIdbSchema'; import { DBType } from './StorageReader'; import { AuthId, FindCertificateFieldsArgs, FindCertificatesArgs, FindCommissionsArgs, FindForUserSincePagedArgs, FindMonitorEventsArgs, FindOutputBasketsArgs, FindOutputsArgs, FindOutputTagMapsArgs, FindOutputTagsArgs, FindProvenTxReqsArgs, FindProvenTxsArgs, FindSyncStatesArgs, FindTransactionsArgs, FindTxLabelMapsArgs, FindTxLabelsArgs, FindUsersArgs, ProvenOrRawTx, PurgeParams, PurgeResults, TrxToken, WalletStorageProvider } from '../sdk/WalletStorage.interfaces'; import { EntityTimeStamp } from '../sdk/types'; export interface StorageIdbOptions extends StorageProviderOptions { } /** * This class implements the `StorageProvider` interface using IndexedDB, * via the promises wrapper package `idb`. */ export declare class StorageIdb extends StorageProvider implements WalletStorageProvider { dbName: string; db?: IDBPDatabase; constructor(options: StorageIdbOptions); /** * This method must be called at least once before any other method accesses the database, * and each time the schema may have updated. * * If the database has already been created in this context, `storageName` and `storageIdentityKey` * are ignored. * * @param storageName * @param storageIdentityKey * @returns */ migrate(storageName: string, storageIdentityKey: string): Promise; /** * Following initial database initialization, this method verfies that db is ready for use. * * @throws `WERR_INVALID_OPERATION` if the database has not been initialized by a call to `migrate`. * * @param storageName * @param storageIdentityKey * * @returns */ verifyDB(storageName?: string, storageIdentityKey?: string): Promise>; /** * Convert the standard optional `TrxToken` parameter into either a direct knex database instance, * or a Knex.Transaction as appropriate. */ toDbTrx(stores: string[], mode: 'readonly' | 'readwrite', trx?: TrxToken): IDBPTransaction; /** * Called by `makeAvailable` to return storage `TableSettings`. * Since this is the first async method that must be called by all clients, * it is where async initialization occurs. * * After initialization, cached settings are returned. * * @param trx */ readSettings(trx?: TrxToken): Promise; initDB(storageName?: string, storageIdentityKey?: string): Promise>; reviewStatus(args: { agedLimit: Date; trx?: TrxToken; }): Promise<{ log: string; }>; purgeData(params: PurgeParams, trx?: TrxToken): Promise; /** * Proceeds in three stages: * 1. Find an output that exactly funds the transaction (if exactSatoshis is not undefined). * 2. Find an output that overfunds by the least amount (targetSatoshis). * 3. Find an output that comes as close to funding as possible (targetSatoshis). * 4. Return undefined if no output is found. * * Outputs must belong to userId and basketId and have spendable true. * Their corresponding transaction must have status of 'completed', 'unproven', or 'sending' (if excludeSending is false). * * @param userId * @param basketId * @param targetSatoshis * @param exactSatoshis * @param excludeSending * @param transactionId * @returns next funding output to add to transaction or undefined if there are none. */ allocateChangeInput(userId: number, basketId: number, targetSatoshis: number, exactSatoshis: number | undefined, excludeSending: boolean, transactionId: number): Promise; getProvenOrRawTx(txid: string, trx?: TrxToken): Promise; getRawTxOfKnownValidTransaction(txid?: string, offset?: number, length?: number, trx?: TrxToken): Promise; private getRawTxForSlice; private getRawTxFull; getLabelsForTransactionId(transactionId?: number, trx?: TrxToken): Promise; getTagsForOutputId(outputId: number, trx?: TrxToken): Promise; listActions(auth: AuthId, vargs: Validation.ValidListActionsArgs): Promise; listOutputs(auth: AuthId, vargs: Validation.ValidListOutputsArgs): Promise; countChangeInputs(userId: number, basketId: number, excludeSending: boolean): Promise; findCertificatesAuth(auth: AuthId, args: FindCertificatesArgs): Promise; findOutputBasketsAuth(auth: AuthId, args: FindOutputBasketsArgs): Promise; findOutputsAuth(auth: AuthId, args: FindOutputsArgs): Promise; insertCertificateAuth(auth: AuthId, certificate: TableCertificateX): Promise; dropAllData(): Promise; /** * Reject undefined values in a `partial` filter argument. Matches * Knex behavior (which throws `Undefined binding(s) detected`) so that * callers can't pass an unmapped idMap lookup through as a silent * match-anything. Omit the key to skip filtering on it; pass null if * you need IS NULL semantics (only meaningful for nullable columns). */ private assertNoUndefinedInPartial; filterOutputTagMaps(args: FindOutputTagMapsArgs, filtered: (v: TableOutputTagMap) => void, userId?: number): Promise; findOutputTagMaps(args: FindOutputTagMapsArgs): Promise; private openProvenTxReqsCursor; filterProvenTxReqs(args: FindProvenTxReqsArgs, filtered: (v: TableProvenTxReq) => void, userId?: number): Promise; findProvenTxReqs(args: FindProvenTxReqsArgs): Promise; filterProvenTxs(args: FindProvenTxsArgs, filtered: (v: TableProvenTx) => void, userId?: number): Promise; findProvenTxs(args: FindProvenTxsArgs): Promise; filterTxLabelMaps(args: FindTxLabelMapsArgs, filtered: (v: TableTxLabelMap) => void, userId?: number): Promise; findTxLabelMaps(args: FindTxLabelMapsArgs): Promise; countOutputTagMaps(args: FindOutputTagMapsArgs): Promise; countProvenTxReqs(args: FindProvenTxReqsArgs): Promise; countProvenTxs(args: FindProvenTxsArgs): Promise; countTxLabelMaps(args: FindTxLabelMapsArgs): Promise; insertCertificate(certificate: TableCertificateX, trx?: TrxToken): Promise; insertCertificateField(certificateField: TableCertificateField, trx?: TrxToken): Promise; insertCommission(commission: TableCommission, trx?: TrxToken): Promise; insertMonitorEvent(event: TableMonitorEvent, trx?: TrxToken): Promise; insertOutput(output: TableOutput, trx?: TrxToken): Promise; insertOutputBasket(basket: TableOutputBasket, trx?: TrxToken): Promise; insertOutputTag(tag: TableOutputTag, trx?: TrxToken): Promise; insertOutputTagMap(tagMap: TableOutputTagMap, trx?: TrxToken): Promise; insertProvenTx(tx: TableProvenTx, trx?: TrxToken): Promise; insertProvenTxReq(tx: TableProvenTxReq, trx?: TrxToken): Promise; insertSyncState(syncState: TableSyncState, trx?: TrxToken): Promise; insertTransaction(tx: TableTransaction, trx?: TrxToken): Promise; insertTxLabel(label: TableTxLabel, trx?: TrxToken): Promise; insertTxLabelMap(labelMap: TableTxLabelMap, trx?: TrxToken): Promise; insertUser(user: TableUser, trx?: TrxToken): Promise; updateIdb(id: number | number[], update: Partial, keyProp: string, storeName: string, trx?: TrxToken): Promise; updateIdbKey(key: Array, update: Partial, keyProps: string[], storeName: string, trx?: TrxToken): Promise; updateCertificate(id: number, update: Partial, trx?: TrxToken): Promise; updateCertificateField(certificateId: number, fieldName: string, update: Partial, trx?: TrxToken): Promise; updateCommission(id: number, update: Partial, trx?: TrxToken): Promise; updateMonitorEvent(id: number, update: Partial, trx?: TrxToken): Promise; updateOutput(id: number, update: Partial, trx?: TrxToken): Promise; updateOutputBasket(id: number, update: Partial, trx?: TrxToken): Promise; updateOutputTag(id: number, update: Partial, trx?: TrxToken): Promise; updateProvenTx(id: number, update: Partial, trx?: TrxToken): Promise; updateProvenTxReq(id: number | number[], update: Partial, trx?: TrxToken): Promise; updateSyncState(id: number, update: Partial, trx?: TrxToken): Promise; updateTransaction(id: number | number[], update: Partial, trx?: TrxToken): Promise; updateTxLabel(id: number, update: Partial, trx?: TrxToken): Promise; updateUser(id: number, update: Partial, trx?: TrxToken): Promise; updateOutputTagMap(outputId: number, tagId: number, update: Partial, trx?: TrxToken): Promise; updateTxLabelMap(transactionId: number, txLabelId: number, update: Partial, trx?: TrxToken): Promise; destroy(): Promise; allStores: string[]; /** * @param scope * @param trx * @returns */ transaction(scope: (trx: TrxToken) => Promise, trx?: TrxToken): Promise; filterCertificateFields(args: FindCertificateFieldsArgs, filtered: (v: TableCertificateField) => void): Promise; findCertificateFields(args: FindCertificateFieldsArgs): Promise; private openCertificatesCursor; filterCertificates(args: FindCertificatesArgs, filtered: (v: TableCertificateX) => void): Promise; findCertificates(args: FindCertificatesArgs): Promise; filterCommissions(args: FindCommissionsArgs, filtered: (v: TableCommission) => void): Promise; findCommissions(args: FindCommissionsArgs): Promise; filterMonitorEvents(args: FindMonitorEventsArgs, filtered: (v: TableMonitorEvent) => void): Promise; findMonitorEvents(args: FindMonitorEventsArgs): Promise; filterOutputBaskets(args: FindOutputBasketsArgs, filtered: (v: TableOutputBasket) => void): Promise; findOutputBaskets(args: FindOutputBasketsArgs): Promise; private openOutputsCursor; filterOutputs(args: FindOutputsArgs, filtered: (v: TableOutput) => void, tagIds?: number[], isQueryModeAll?: boolean): Promise; private outputMatchesTags; findOutputs(args: FindOutputsArgs, tagIds?: number[], isQueryModeAll?: boolean): Promise; filterOutputTags(args: FindOutputTagsArgs, filtered: (v: TableOutputTag) => void): Promise; findOutputTags(args: FindOutputTagsArgs): Promise; filterSyncStates(args: FindSyncStatesArgs, filtered: (v: TableSyncState) => void): Promise; findSyncStates(args: FindSyncStatesArgs): Promise; private openTransactionsCursor; filterTransactions(args: FindTransactionsArgs, filtered: (v: TableTransaction) => void, labelIds?: number[], isQueryModeAll?: boolean): Promise; private transactionMatchesLabels; findTransactions(args: FindTransactionsArgs, labelIds?: number[], isQueryModeAll?: boolean): Promise; filterTxLabels(args: FindTxLabelsArgs, filtered: (v: TableTxLabel) => void): Promise; findTxLabels(args: FindTxLabelsArgs): Promise; private matchesUserPartial; filterUsers(args: FindUsersArgs, filtered: (v: TableUser) => void): Promise; findUsers(args: FindUsersArgs): Promise; countCertificateFields(args: FindCertificateFieldsArgs): Promise; countCertificates(args: FindCertificatesArgs): Promise; countCommissions(args: FindCommissionsArgs): Promise; countMonitorEvents(args: FindMonitorEventsArgs): Promise; countOutputBaskets(args: FindOutputBasketsArgs): Promise; countOutputs(args: FindOutputsArgs, tagIds?: number[], isQueryModeAll?: boolean): Promise; countOutputTags(args: FindOutputTagsArgs): Promise; countSyncStates(args: FindSyncStatesArgs): Promise; countTransactions(args: FindTransactionsArgs, labelIds?: number[], isQueryModeAll?: boolean): Promise; countTxLabels(args: FindTxLabelsArgs): Promise; countUsers(args: FindUsersArgs): Promise; getProvenTxsForUser(args: FindForUserSincePagedArgs): Promise; getProvenTxReqsForUser(args: FindForUserSincePagedArgs): Promise; getTxLabelMapsForUser(args: FindForUserSincePagedArgs): Promise; getOutputTagMapsForUser(args: FindForUserSincePagedArgs): Promise; verifyReadyForDatabaseAccess(trx?: TrxToken): Promise; /** * Helper to force uniform behavior across database engines. * Use to process all individual records with time stamps or number[] retreived from database. */ validateEntity(entity: T, dateFields?: string[], booleanFields?: string[]): T; private applyDateFields; private applyBooleanFields; private normalizeEntityValues; /** * Helper to force uniform behavior across database engines. * Use to process all arrays of records with time stamps retreived from database. * @returns input `entities` array with contained values validated. */ validateEntities(entities: T[], dateFields?: string[], booleanFields?: string[]): T[]; /** * Helper to force uniform behavior across database engines. * Use to process the update template for entities being updated. */ validatePartialForUpdate(update: Partial, dateFields?: string[], booleanFields?: string[]): Partial; private applyOptionalDateFields; private applyIntegerBooleanFields; private normalizeForStorage; /** * Helper to force uniform behavior across database engines. * Use to process new entities being inserted into the database. */ validateEntityForInsert(entity: T, trx?: TrxToken, dateFields?: string[], booleanFields?: string[]): Promise; validateRawTransaction(t: TableTransaction, trx?: TrxToken): Promise; adminStats(adminIdentityKey: string): Promise; } //# sourceMappingURL=StorageIdb.d.ts.map