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 { Knex } from 'knex'; import { AdminStatsResult, StorageProvider, StorageProviderOptions } from './StorageProvider'; import { DBType } from './StorageReader'; import { AuthId, FindCertificateFieldsArgs, FindCertificatesArgs, FindCommissionsArgs, FindForUserSincePagedArgs, FindMonitorEventsArgs, FindOutputBasketsArgs, FindOutputsArgs, FindOutputTagMapsArgs, FindOutputTagsArgs, FindPartialSincePagedArgs, FindProvenTxReqsArgs, FindProvenTxsArgs, FindStaleMerkleRootsArgs, FindSyncStatesArgs, FindTransactionsArgs, FindTxLabelMapsArgs, FindTxLabelsArgs, FindUsersArgs, ProvenOrRawTx, PurgeParams, PurgeResults, TrxToken, WalletStorageProvider } from '../sdk/WalletStorage.interfaces'; import { EntityTimeStamp } from '../sdk/types'; export interface StorageKnexOptions extends StorageProviderOptions { /** * Knex database interface initialized with valid connection configuration. */ knex: Knex; } export declare class StorageKnex extends StorageProvider implements WalletStorageProvider { knex: Knex; constructor(options: StorageKnexOptions); readSettings(): Promise; getProvenOrRawTx(txid: string, trx?: TrxToken): Promise; dbTypeSubstring(source: string, fromOffset: number, forLength?: number): string; private normaliseKnexRawResult; private getRawTxSlice; getRawTxOfKnownValidTransaction(txid?: string, offset?: number, length?: number, trx?: TrxToken): Promise; getProvenTxsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder; getProvenTxsForUser(args: FindForUserSincePagedArgs): Promise; getProvenTxReqsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder; getProvenTxReqsForUser(args: FindForUserSincePagedArgs): Promise; getTxLabelMapsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder; getTxLabelMapsForUser(args: FindForUserSincePagedArgs): Promise; getOutputTagMapsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder; getOutputTagMapsForUser(args: FindForUserSincePagedArgs): Promise; listActions(auth: AuthId, vargs: Validation.ValidListActionsArgs): Promise; listOutputs(auth: AuthId, vargs: Validation.ValidListOutputsArgs): Promise; insertProvenTx(tx: TableProvenTx, trx?: TrxToken): Promise; insertProvenTxReq(tx: TableProvenTxReq, trx?: TrxToken): Promise; insertUser(user: TableUser, trx?: TrxToken): Promise; insertCertificateAuth(auth: AuthId, certificate: TableCertificateX): Promise; insertCertificate(certificate: TableCertificateX, trx?: TrxToken): Promise; insertCertificateField(certificateField: TableCertificateField, trx?: TrxToken): Promise; insertOutputBasket(basket: TableOutputBasket, trx?: TrxToken): Promise; insertTransaction(tx: TableTransaction, trx?: TrxToken): Promise; insertCommission(commission: TableCommission, trx?: TrxToken): Promise; insertOutput(output: TableOutput, trx?: TrxToken): Promise; insertOutputTag(tag: TableOutputTag, trx?: TrxToken): Promise; insertOutputTagMap(tagMap: TableOutputTagMap, trx?: TrxToken): Promise; insertTxLabel(label: TableTxLabel, trx?: TrxToken): Promise; insertTxLabelMap(labelMap: TableTxLabelMap, trx?: TrxToken): Promise; insertMonitorEvent(event: TableMonitorEvent, trx?: TrxToken): Promise; insertSyncState(syncState: TableSyncState, trx?: TrxToken): Promise; updateCertificateField(certificateId: number, fieldName: string, update: Partial, trx?: TrxToken): Promise; updateCertificate(id: number, update: Partial, trx?: TrxToken): Promise; updateCommission(id: number, update: Partial, trx?: TrxToken): Promise; updateOutputBasket(id: number, update: Partial, trx?: TrxToken): Promise; updateOutput(id: number, update: Partial, trx?: TrxToken): Promise; updateOutputTagMap(outputId: number, tagId: number, update: Partial, trx?: TrxToken): Promise; updateOutputTag(id: number, update: Partial, trx?: TrxToken): Promise; updateProvenTxReq(id: number | number[], update: Partial, trx?: TrxToken): Promise; updateProvenTx(id: number, update: Partial, trx?: TrxToken): Promise; updateSyncState(id: number, update: Partial, trx?: TrxToken): Promise; updateTransaction(id: number | number[], update: Partial, trx?: TrxToken): Promise; updateTxLabelMap(transactionId: number, txLabelId: number, update: Partial, trx?: TrxToken): Promise; updateTxLabel(id: number, update: Partial, trx?: TrxToken): Promise; updateUser(id: number, update: Partial, trx?: TrxToken): Promise; updateMonitorEvent(id: number, update: Partial, trx?: TrxToken): Promise; setupQuery(table: string, args: FindPartialSincePagedArgs): Knex.QueryBuilder; findCertificateFieldsQuery(args: FindCertificateFieldsArgs): Knex.QueryBuilder; findCertificatesQuery(args: FindCertificatesArgs): Knex.QueryBuilder; findCommissionsQuery(args: FindCommissionsArgs): Knex.QueryBuilder; findOutputBasketsQuery(args: FindOutputBasketsArgs): Knex.QueryBuilder; findOutputsQuery(args: FindOutputsArgs, count?: boolean): Knex.QueryBuilder; findOutputTagMapsQuery(args: FindOutputTagMapsArgs): Knex.QueryBuilder; findOutputTagsQuery(args: FindOutputTagsArgs): Knex.QueryBuilder; findProvenTxReqsQuery(args: FindProvenTxReqsArgs): Knex.QueryBuilder; findProvenTxsQuery(args: FindProvenTxsArgs): Knex.QueryBuilder; findStaleMerkleRootsQuery(args: FindStaleMerkleRootsArgs): Knex.QueryBuilder; findSyncStatesQuery(args: FindSyncStatesArgs): Knex.QueryBuilder; findTransactionsQuery(args: FindTransactionsArgs, count?: boolean): Knex.QueryBuilder; findTxLabelMapsQuery(args: FindTxLabelMapsArgs): Knex.QueryBuilder; findTxLabelsQuery(args: FindTxLabelsArgs): Knex.QueryBuilder; findUsersQuery(args: FindUsersArgs): Knex.QueryBuilder; findMonitorEventsQuery(args: FindMonitorEventsArgs): Knex.QueryBuilder; findCertificatesAuth(auth: AuthId, args: FindCertificatesArgs): Promise; findOutputBasketsAuth(auth: AuthId, args: FindOutputBasketsArgs): Promise; findOutputsAuth(auth: AuthId, args: FindOutputsArgs): Promise; findCertificateFields(args: FindCertificateFieldsArgs): Promise; findCertificates(args: FindCertificatesArgs): Promise; findCommissions(args: FindCommissionsArgs): Promise; findOutputBaskets(args: FindOutputBasketsArgs): Promise; findOutputs(args: FindOutputsArgs): Promise; findOutputTagMaps(args: FindOutputTagMapsArgs): Promise; findOutputTags(args: FindOutputTagsArgs): Promise; findProvenTxReqs(args: FindProvenTxReqsArgs): Promise; findProvenTxs(args: FindProvenTxsArgs): Promise; findStaleMerkleRoots(args: FindStaleMerkleRootsArgs): Promise; findSyncStates(args: FindSyncStatesArgs): Promise; findTransactions(args: FindTransactionsArgs): Promise; findTxLabelMaps(args: FindTxLabelMapsArgs): Promise; findTxLabels(args: FindTxLabelsArgs): Promise; findUsers(args: FindUsersArgs): Promise; recentlyActiveUsers(limit?: number, trx?: TrxToken): Promise; findMonitorEvents(args: FindMonitorEventsArgs): Promise; getCount(q: Knex.QueryBuilder): Promise; countCertificateFields(args: FindCertificateFieldsArgs): Promise; countCertificates(args: FindCertificatesArgs): Promise; countCommissions(args: FindCommissionsArgs): Promise; countOutputBaskets(args: FindOutputBasketsArgs): Promise; countOutputs(args: FindOutputsArgs): Promise; countOutputTagMaps(args: FindOutputTagMapsArgs): Promise; countOutputTags(args: FindOutputTagsArgs): Promise; countProvenTxReqs(args: FindProvenTxReqsArgs): Promise; countProvenTxs(args: FindProvenTxsArgs): Promise; countSyncStates(args: FindSyncStatesArgs): Promise; countTransactions(args: FindTransactionsArgs): Promise; countTxLabelMaps(args: FindTxLabelMapsArgs): Promise; countTxLabels(args: FindTxLabelsArgs): Promise; countUsers(args: FindUsersArgs): Promise; countMonitorEvents(args: FindMonitorEventsArgs): Promise; destroy(): Promise; migrate(storageName: string, storageIdentityKey: string): Promise; dropAllData(): Promise; transaction(scope: (trx: TrxToken) => Promise, trx?: TrxToken): Promise; /** * Convert the standard optional `TrxToken` parameter into either a direct knex database instance, * or a Knex.Transaction as appropriate. */ toDb(trx?: TrxToken): Knex | Knex.Transaction; validateRawTransaction(t: TableTransaction, trx?: TrxToken): Promise; _verifiedReadyForDatabaseAccess: boolean; /** * Make sure database is ready for access: * * - dateScheme is known * - foreign key constraints are enabled * * @param trx */ verifyReadyForDatabaseAccess(trx?: TrxToken): Promise; /** Convert every number-array value to a Buffer and every undefined to null on an arbitrary object. */ private serialiseForKnex; /** Apply optional date-field coercion list in-place. */ private coerceDateFields; /** Apply optional boolean-field coercion list in-place. */ private coerceBooleanFields; /** * 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; /** * 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; getLabelsForTransactionId(transactionId?: number, trx?: TrxToken): Promise; getTagsForOutputId(outputId: number, trx?: TrxToken): Promise; purgeData(params: PurgeParams, trx?: TrxToken): Promise; reviewStatus(args: { agedLimit: Date; trx?: TrxToken; }): Promise<{ log: string; }>; /** * Counts the outputs for userId in basketId that are spendable: true * AND whose transaction status is one of: * - completed * - unproven * - sending (if excludeSending is false) */ countChangeInputs(userId: number, basketId: number, excludeSending: boolean): Promise; findOutputsByIds(outputIds: number[], trx?: TrxToken): Promise>; findOutputsByOutpoints(userId: number, outpoints: Array<{ txid: string; vout: number; }>, trx?: TrxToken): Promise>; findOrInsertOutputBasketsBulk(userId: number, names: string[], trx?: TrxToken): Promise>; findOrInsertOutputTagsBulk(userId: number, tags: string[], trx?: TrxToken): Promise>; sumSpendableSatoshisInBasket(userId: number, basketId: number, excludeSending: boolean, trx?: TrxToken): Promise; /** * Finds closest matching available change output to use as input for new transaction. * * Transactionally allocate the output such that */ allocateChangeInput(userId: number, basketId: number, targetSatoshis: number, exactSatoshis: number | undefined, excludeSending: boolean, transactionId: number): Promise; /** Convert null→undefined and Buffer→number[] on a retrieved entity in-place. */ private deserialiseFromKnex; /** * Helper to force uniform behavior across database engines. * Use to process all individual records with time stamps retreived from database. */ validateEntity(entity: T, dateFields?: string[], booleanFields?: string[]): T; /** * 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[]; adminStats(adminIdentityKey: string): Promise; } //# sourceMappingURL=StorageKnex.d.ts.map