import { a as Storage, C as Connection, T as Trace, S as Selector, f as DatabaseMetadata, N as NamespaceMetadata, M as MetadataFor } from '../shared/hive.DlaRxYsk.js'; import { Logger } from './logger.js'; import './transaction.js'; import 'zod'; import '../streams/index.js'; //#region src/index.d.ts /** * Minimal required options for an `Index` implementation. */ interface IndexOptions { /** * Storage instance the Index belongs to. */ storage: Storage; /** * Database handle to use for the Index. */ connection: Connection; /** * Logger instance to use for logging. */ logger?: Logger | null | undefined; } /** * Base row structure for a row stored in an `Index` implementation. */ interface IndexRow { id: string; key: string; type: Selector['type']; parent: string | null; size: number | null; indexed_at: number; created_at: number | null; modified_at: number | null; } declare abstract class Index { /** * Logger instance to collect logs from the `Index` instance. */ readonly logger: Logger | null; /** * Storage instance the `Index` instance belongs to. */ readonly storage: Storage; /** * SQLite `Connection` instance the `Index` uses to store state in. */ readonly connection: Connection; /** * Map containin references of pending operations on the `Index` instance. */ pending: { start: Promise | null; stop: Promise | null; refresh: Promise | null; }; constructor(opts: IndexOptions); /** * Start the `Index` instance. * * To prevent race conditions, repeated calls to this method return the same * Promise, ensuring the `Index` start is only performed once at a time. * * @param opts Options for starting the `Index` instance. * * @returns Promise resolving the `Index` instance once it has started. */ abstract start: (opts?: { /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexStartEvent` when the `Index` instance * has started. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise; /** * Stop the `Index` instance. * * To prevent race conditions, repeated calls to this method return the same * Promise, ensuring the `Index` stop is only performed once at a time. * * @param opts Options for stopping the `Index` instance. * * @returns Promise resolving the `Index` instance once it has stopped. */ abstract stop: (opts?: { /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexStopEvent` when the `Index` instance * has stopped. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise; /** * Refresh the `Index` instance. * * To prevent race conditions, repeated calls to this method return the same * Promise, ensuring the `Index` refresh is only performed once at a time. * * @param opts Options for refreshing the `Index` instance. * * @returns Promise resolving the `Index` instance once it has refreshed. */ abstract refresh: (opts?: { /** * Optional parent Resource to refresh the children of. * * @default `null` */ parent?: Selector<'namespace' | 'database'> | null | undefined; /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexRefreshEvent` when the `Index` instance * has refreshed. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise; /** * List the Resources inside the `Index` instance. * * @param opts Options for listing the Resources inside the `Index` instance. * * @returns Promise resolving the Metadata objects of the stored Resources. */ abstract list: (opts?: { /** * Optional parent Resource to list the children of. * * @default `null` */ parent?: Selector<'namespace' | 'database'> | null | undefined; /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexListEvent` when the Resources have been * listed. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise>; /** * Get a specific Resource from the `Index` instance. * * @param selector Selector of the Resource to get. * @param opts Options for getting the Resource. * * @throws `ResourceNotFoundError` if the Resource was not found. * * @returns Promise resolving the metadata of the requested Resource. */ abstract get: (selector: Selector, opts?: { /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexGetEvent` when the Resource has been * retrieved. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise>; /** * Add a Resource to the `Index` instance. * * @param selector Selector of the Resource to add. * @param metadata Metadata of the Resource to add. * @param opts Options for adding the Resource. * * @throws `ResourceExistsError` if the Resource already exists. * * @returns Promise resolving the `Index` instance once the Resource has been added. */ abstract add: ( /** * Selector of the Resource to add. */ selector: Selector, /** * Metadata of the Resource to add. */ metadata: DatabaseMetadata | NamespaceMetadata, /** * Options for adding the Resource. */ opts?: { /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexAddEvent` when the Resource has been * added. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise; /** * Update a Resource in the `Index` instance. * * @param selector Selector of the Resource to update. * @param metadata Metadata of the Resource to update. * @param opts Options for updating the Resource. * * @throws `ResourceNotFoundError` if the Resource was not found. * @throws `ResourceExistsError` if the Resource already exists. * * @returns Promise resolving the updated metadata of the updated Resource. */ abstract update: ( /** * Selector of the Resource to update. */ selector: Selector, /** * Metadata of the Resource to update. */ metadata: Pick | Pick, /** * Options for updating the Resource. */ opts?: { /** * Trace to associate the operation with. * * @default `null` */ trace?: Trace | null | undefined; /** * Whether to emit a `IndexUpdateEvent` when the Resource has been * updated. * * @default `true` */ emit?: boolean | null | undefined; }) => Promise>; /** * Remove a Resource from the `Index` instance. * * @param selector Selector of the Resource to remove. * @param opts Options for removing the Resource. * * @throws `ResourceNotFoundError` if the Resource was not found. * * @returns Promise resolving when the Resource has been removed. */ abstract remove: (selector: Selector, opts?: { trace?: Trace | null | undefined; emit?: boolean | null | undefined; }) => Promise; } export { Index }; export type { IndexOptions, IndexRow };