/** * @fileoverview Generic BrightChain database initialization function. * * This is the Suite's generic version of the database init — it creates * the block store and BrightDb instance based on environment configuration, * but does NOT create domain-specific stores (MemberStore, EnergyAccountStore). * * Domain-specific model registrations are passed in via an optional callback. * Pool security setup is also passed in via an optional callback to avoid * circular dependencies between node-express-suite and api-lib. * * @module databaseInit */ import type { IBlockStore, ICloudBlockStoreConfig, IInitResult } from '@brightchain/brightchain-lib'; import { BlockSize, BlockStoreType } from '@brightchain/brightchain-lib'; import { BrightDb } from '@brightchain/db'; /** * Minimal environment interface required by the generic database init. * Consumers pass an object satisfying this shape — it does NOT depend on * api-lib's full Environment class. */ export interface IDatabaseInitEnvironment { blockStorePath?: string; blockStoreBlockSizes: readonly BlockSize[]; blockStoreType: BlockStoreType; devDatabasePoolName?: string; azureConfig?: ICloudBlockStoreConfig & Record; s3Config?: ICloudBlockStoreConfig & Record; memberPoolName: string; /** * System user's ECDSA public key (compressed secp256k1, hex string). * When set along with systemPrivateKeyHex, pool security enforcement * is enabled at runtime (signed writes via AuthorizedHeadRegistry). */ systemPublicKeyHex?: string; /** * System user's ECDSA private key (hex string). * Required for auto-signing local writes when pool security is enabled. */ systemPrivateKeyHex?: string; } /** * The backend data returned on successful generic database init. * Does NOT include domain-specific stores — those are added by the caller. */ export interface IGenericInitData { blockStore: IBlockStore; db: BrightDb; } /** * Context passed to the poolSecuritySetup callback. * Contains everything the caller needs to set up pool security * without node-express-suite needing to know about api-lib types. */ export interface IPoolSecuritySetupContext { /** The initial BrightDb instance (before pool security). */ db: BrightDb; /** The block store backing the db. */ blockStore: IBlockStore; /** The environment config. */ environment: IDatabaseInitEnvironment; } /** * Result from the poolSecuritySetup callback. * If pool security was configured, returns the new BrightDb instance * that has write enforcement enabled. */ export interface IPoolSecuritySetupResult { /** The (possibly new) BrightDb instance with pool security enabled. */ db: BrightDb; } /** * Initialize the BrightChain database stack (generic version). * * Creates a block store and BrightDb instance based on environment config. * Optionally calls a `modelRegistrations` callback after db.connect() so * that the caller can register domain-specific models (e.g. energy_accounts). * * Pool security setup is handled via an optional `poolSecuritySetup` callback * to avoid circular dependencies — the caller (api-lib) provides the * implementation that knows about ECDSANodeAuthenticator, ACL deserialization, * and the audit ledger. * * @param environment - Object satisfying IDatabaseInitEnvironment * @param options.modelRegistrations - Optional callback to register models on the BrightDb instance. * @param options.poolSecuritySetup - Optional callback to configure pool security (ACL enforcement, ledger). * @returns An IInitResult containing { blockStore, db } on success, * or a failure result with a descriptive error message. */ export declare function brightchainDatabaseInit(environment: IDatabaseInitEnvironment, options?: { modelRegistrations?: (db: BrightDb, blockStore: IBlockStore) => void | Promise; poolSecuritySetup?: (context: IPoolSecuritySetupContext) => Promise; }): Promise>; //# sourceMappingURL=databaseInit.d.ts.map