import type { Store, StoreIndexOptions, StoreItem, StoreNamespace, StorePutOptions, StoreSearchOptions } from '../types/store.js'; import type { MigrationResult, SchemaMigration } from '../utils/schema-migrations.js'; import { type PostgresLikeClient } from './client.js'; import type { PostgresMigrateOptions } from './migrations.js'; /** Options for the Postgres store. */ export interface PostgresStoreOptions { /** Table name, optionally schema-qualified. Defaults to `nexus_store`. */ table?: string; /** Enables semantic search by embedding indexed fields on write. */ index?: StoreIndexOptions; /** * Stores embeddings as a pgvector column of this many dimensions and ranks in the database. The * extension must be installed. Without it, embeddings are kept as JSON and ranked in process, * which works on any Postgres and suits namespaces of a few thousand items. */ vectorDimensions?: number; /** Replaces the system clock, for tests. */ now?: () => Date; } /** * The versioned schema, which `migrate()` and `nexus db migrate` apply. Version 1 is the 2.0 schema. */ export declare function storeMigrations(options?: Pick): SchemaMigration[]; /** The schema, as statements. With `vectorDimensions`, pgvector's extension is created too. */ export declare function storeMigration(options?: Pick): string[]; /** * Long-term memory in Postgres, with pgvector when it is available. * * The same contract as `MemoryStore` and `RedisStore`, checked by the same tests. Namespace prefixes * are matched on a `C`-collated key, so `['tenant-7']` never matches `['tenant-70']` and an index * serves the match. Expired items are hidden from every read at once; `sweep()` deletes them, for a * retention job. */ export declare class PostgresStore implements Store { private readonly client; private readonly options; private readonly table; private readonly now; constructor(client: PostgresLikeClient, options?: PostgresStoreOptions); /** * Applies this store's pending migrations, recorded in `nexus_schema_migrations`, under a lock. * Never runs implicitly. Safe on a database an older release created: what exists is kept. */ migrate(options?: PostgresMigrateOptions): Promise; /** Stores an item, keeping its original `createdAt` when it replaces one. */ put(namespace: StoreNamespace, key: string, value: V, options?: StorePutOptions): Promise; /** * Stores an item only when the stored one's `version` is `expected`, or, with `expected` `null`, * only when none is stored. One statement, so two writers deciding on one version cannot both win. */ putIfVersion(namespace: StoreNamespace, key: string, value: V, expected: number | null): Promise; /** Reads an item, or `undefined` when it does not exist or has expired. */ get(namespace: StoreNamespace, key: string): Promise | undefined>; /** Deletes an item. */ delete(namespace: StoreNamespace, key: string): Promise; /** * Items under a namespace prefix, newest first, or ranked by similarity when a query is given. * Defaults to 20. */ search(namespacePrefix: StoreNamespace, options?: StoreSearchOptions): Promise>>; /** Namespaces under a prefix. Defaults to 100. */ listNamespaces(options?: { prefix?: StoreNamespace; limit?: number; }): Promise; /** Deletes expired items, returning how many went. Reads already hide them. */ sweep(): Promise; private embed; }