import { a as Storage, b as Driver, E as EventEmitter, j as EventMap, U as UnexpectedErrorEvent, T as Trace, S as Selector, f as DatabaseMetadata, N as NamespaceMetadata, g as SelectorInput, e as CreateResourceOptions, I as InstanceFor, M as MetadataFor, D as Database } from './shared/hive.DlaRxYsk.js'; export { i as Namespace } from './shared/hive.DlaRxYsk.js'; import { RowObject, RowValues, TransactionInput, TransactionResult } from './sdk/transaction.js'; import { Logger } from './sdk/logger.js'; import 'zod'; import './streams/index.js'; type HiveConfig = { /** * Unique instance identifier, primarily used during logging. * * @default crypto.randomUUID() */ id?: string | null | undefined; /** * Driver instance wrapping a runtime-specific implementation of SQLite. * * The Driver will be provided to the Storage instance during initialization. * * @default null */ driver?: Driver | null | undefined; /** * Storage instance to use for persisting state. * * @example ``` * new Hive({ * driver: new BunDriver(), * storage: new MemoryStorage(), * }); * ``` * * @example ``` * new Hive({ * driver: new BunDriver(), * storage: new DiskStorage({ dir: '.state/' }), * }); * ``` * * @example ``` * new Hive({ * driver: new BunDriver(), * storage: new S3Storage({ * dir: '.state/', * s3: { * host: 'https://s3.acme.co/state', * bucket: 'state', * accessKeyId: 'my-access-key-id', * secretAccessKey: 'my-secret-access-key', * }, * }), * }); * ``` */ storage: S; /** * Logger instance to use for logging. * * The Logger will be provided to the Storage instance during initialization. * * @default null */ logger?: Logger | null | undefined; /** * EventEmitter instance to use for emitting events. * * The EventEmitter will be provided to the Storage instance * during initialization. * * @default null */ events?: EventEmitter | null | undefined; /** * Error handler to invoke with any errors which might occur during * background tasks. * * @default null */ onError?: ((event: UnexpectedErrorEvent) => void) | null | undefined; }; declare class Hive { static readonly name = "hive"; /** * Unique identifier for the `Hive` instance. * * Used primarily for communication and logging. */ readonly id: string; /** * Driver instance wrapping a runtime-specific implementation of SQLite. */ readonly driver: Driver | null; /** * Storage implementation the `Hive` instance manages. */ readonly storage: S; /** * EventEmitter instance internal events are emitted through. */ readonly events: EventEmitter; /** * Logger instance the `Hive` instance uses for logging. */ readonly logger: Logger | null; /** * Error handler invoked when an error occurs. */ readonly onError: (event: UnexpectedErrorEvent) => void; /** * If currently starting, the Promise resolving when the Hive instance * has started. */ starting: Promise | null; /** * If currently stopping, the Promise resolving when the Hive instance * has stopped. */ stopping: Promise | null; constructor(config: HiveConfig); /** * Starts the `Hive` instance. * * This method is automatically called by the `Hive` constructor. It * initializes and starts all configured components in the correct order. * * To prevent race conditions, repeated calls to this method return the same * Promise, ensuring the `Hive` is started only once. * * @param opts Options for starting the `Hive` instance. * * @returns Promise resolving the `Hive` instance once it has started. */ readonly start: (opts?: { trace?: Trace | null | undefined; }) => Promise; /** * Stops the `Hive` instance. * * This method ensures that all pending operations are completed and all * components are stopped in the correct order, ensuring no state is lost. * * To prevent race conditions, repeated calls to this method return the same * Promise, ensuring the `Hive` is stopped only once. * * @param opts Options for stopping the `Hive` instance. * * @returns Promise resolving the `Hive` instance once it has stopped. */ readonly stop: (opts?: { trace?: Trace | null | undefined; }) => Promise; /** * List all Resources matching the provided filter. * * @param opts Options for listing the Resources. * * @example ``` * // List all top-level Resources. * const resources = await hive.list(); * ``` * * @example ``` * // List all child Resources of a specific Resource. * const children = await hive.list({ * parent: { * type: 'database', * id: 'my-db', * }, * }); * ``` * * @returns Promise resolving an Array containing the Metadata for the * listed Resources. */ list(opts?: { parent?: Selector<'namespace' | 'database'> | null | undefined; trace?: Trace | null | undefined; }): Promise>; /** * Create a new Resource. * * @param resource Details of the Resource to create. * @param opts Options for creating the Resource. * * @example ``` * // Create a new Resource. * await hive.create({ * type: 'database', * id: 'my-database', // Optional. * contents: new Uint8Array(), // Optional. * }); * ``` * * @returns Promise resolving to the created Resource. */ create(resource: Selector | SelectorInput, opts?: CreateResourceOptions): Promise<{ resource: InstanceFor; metadata: MetadataFor; }>; /** * Check if a Resource exists. * * @param resource Details of the Resource to check. * @param opts Options for checking the Resource. * * @example ``` * // Check if a Resource exists. * const exists = await hive.has({ * type: 'database', * id: 'my-database', * }); * ``` * * @returns Promise resolving a boolean indicating whether the Resource exists. */ has(resource: Selector | SelectorInput, opts?: { trace?: Trace | null | undefined; }): Promise; /** * Get a Resource. * * @param resource Details of the Resource to get. * @param opts Options for getting the Resource. * * @example ``` * // Get a Database. * const database = await hive.get({ * type: 'database', * id: 'my-database', * }); * ``` * * @returns Promise resolving the requested Resource and its metadata. */ get(resource: Selector | SelectorInput, opts?: { trace?: Trace | null | undefined; }): Promise<{ resource: Database; metadata: DatabaseMetadata; }>; query = ReadonlyArray>(resource: Selector<'database' | 'snapshot' | 'branch'> | SelectorInput<'database' | 'snapshot' | 'branch'>, input: TransactionInput, opts?: { trace?: Trace | null | undefined; }): Promise>; /** * Free a Resource. * * @param resource Details of the Resource to free. * @param opts Options for freeing the Resource. * * @example ``` * // Free a Database. * await hive.free({ * type: 'database', * id: 'my-database', * }); * ``` * * @returns Promise resolving once the Resource has been freed. */ free(resource: Selector | SelectorInput, opts?: { trace?: Trace | null | undefined; }): Promise; /** * Delete a Resource. * * @param resource Details of the Resource to delete. * @param opts Options for deleting the Resource. * * @example ``` * // Delete a Database. * await hive.delete({ * type: 'database', * id: 'my-database', * }); * ``` * * @returns Promise resolving once the Resource has been deleted. */ delete(resource: Selector | SelectorInput, opts?: { trace?: Trace | null | undefined; }): Promise; } export { Database, Hive, Selector };