/** * @fileoverview Generic BrightDB database plugin for the express-suite plugin architecture. * * Implements IDatabasePlugin to encapsulate the generic BrightDB database * lifecycle: block stores, BrightDb connection/disconnection, and typed accessors. * Domain-specific stores (MemberStore, EnergyAccountStore, etc.) are added by * subclasses in consuming libraries. * * @module plugins/bright-db-database-plugin */ import type { IBlockStore } from '@brightchain/brightchain-lib'; import { MemberStore } from '@brightchain/brightchain-lib'; import type { BrightDb } from '@brightchain/db'; import type { PlatformID } from '@digitaldefiance/node-ecies-lib'; import type { IApplication, IAuthenticationProvider, IDatabasePlugin } from '@digitaldefiance/node-express-suite'; import type { IDatabase } from '@digitaldefiance/suite-core-lib'; import { BrightDbDocumentStoreAdapter } from '../datastore/bright-db-document-store-adapter'; import type { DocumentStore } from '../datastore/document-store'; import type { BrightDbEnvironment } from '../environment'; export interface IBrightDbDatabasePluginOptions { skipAutoSeed?: boolean; } export declare class BrightDbDatabasePlugin implements IDatabasePlugin { readonly name: string; readonly version: string; protected readonly _environment: BrightDbEnvironment; protected readonly _skipAutoSeed: boolean; protected _connected: boolean; protected _blockStore: IBlockStore | null; protected _brightDb: BrightDb | null; protected _authProvider: IAuthenticationProvider | null; /** MemberStore created during init() — shared with the auth service. */ protected _initMemberStore: MemberStore | null; constructor(environment: BrightDbEnvironment, options?: IBrightDbDatabasePluginOptions); /** * The IDatabase instance this plugin manages. * BrightDb implements IDatabase directly, so no adapter is needed. * @throws Error if the plugin is not connected. */ get database(): IDatabase; /** * Authentication provider created during init(). * Returns undefined before init() is called. */ get authenticationProvider(): IAuthenticationProvider | undefined; /** * Connect the BrightDB database stack. * * Calls brightchainDatabaseInit(environment) and stores the resulting * backend references (blockStore, BrightDb). * * @param _uri - Ignored; BrightDB uses environment-based configuration. * @throws Error if brightchainDatabaseInit() returns a failure result. */ connect(_uri?: string): Promise; /** * Disconnect and release all backend references. * Idempotent — calling when already disconnected completes without error. */ disconnect(): Promise; /** * Whether the database is currently connected. */ isConnected(): boolean; /** * Initialize the plugin after connection. * * NOTE: This method intentionally does NOT call initializeDevStore(). * The upstream Application.start() in @digitaldefiance/node-express-suite * already calls initializeDevStore() explicitly after plugins.initAll(), * so calling it here would cause double-seeding (two sets of credentials * with different mnemonics, the first of which becomes stale). * * Subclasses override to create domain-specific auth providers and should * call `super.init(app)` for any base-level initialization. */ init(app: IApplication): Promise; /** * Stop the plugin. Delegates to disconnect() for cleanup. */ stop(): Promise; /** * Provision an ephemeral dev/test block store. * BrightChain doesn't use connection URIs — returns empty string. */ setupDevStore(): Promise; /** * Tear down the ephemeral dev/test block store. * disconnect() handles all cleanup — nothing extra needed. */ teardownDevStore(): Promise; /** * Seed the dev database after connection. * * Creates three members (system, admin, member) using MemberStore and * prints their credentials to the console so the user can log in. * * After seeding, updates the environment's systemMnemonic so that * SystemUserService.getSystemUser() can reconstruct the system member * for request signing (e.g. requestDirectLogin challenge generation). * * Subclasses override with domain-specific seeding (e.g. full RBAC). */ initializeDevStore(): Promise; protected _documentStoreAdapter: BrightDbDocumentStoreAdapter | null; /** * Raw database connection object (IDatabasePlugin.db). * The upstream Application.get db() delegates to this property so that * `application.db` returns a DocumentStore-compatible wrapper around BrightDb. */ get db(): DocumentStore | undefined; /** * The block store backing the BrightDB database. * @throws Error if the plugin is not connected. */ get blockStore(): IBlockStore; /** * The BrightDb instance (implements IDatabase). * @throws Error if the plugin is not connected. */ get brightDb(): BrightDb; } //# sourceMappingURL=bright-db-database-plugin.d.ts.map