import { Extension, PGlite } from '@electric-sql/pglite'; import { PgliteDatabase } from 'drizzle-orm/pglite'; import { d as FulltextStrategy, S as SchemaProvisioning, A as AdapterBackend } from '../../types-BynPp5kU.cjs'; export { C as ContributionDiagnostic, a as ContributionDiagnosticState, b as ContributionRepairEntry, c as ContributionRepairResult, G as GraphIdentityConfig } from '../../types-BynPp5kU.cjs'; import { a as AnyPgTransaction } from '../../postgres-execution-fKW0qRiN.cjs'; export { A as AnyPgDatabase } from '../../postgres-execution-fKW0qRiN.cjs'; import { a as PostgresTables } from '../../postgres-DOBXcZVg.cjs'; import 'zod'; import 'drizzle-orm/pg-core'; import 'drizzle-orm/relations'; /** * Local PGlite backend — Postgres-in-WASM, running in-process. * * [PGlite](https://pglite.dev/) is a full Postgres compiled to WebAssembly * that runs inside the Node/Bun/Deno/browser process with no server and no * native addon. This is the batteries-included Postgres analog of * `createLocalSqliteBackend`: it constructs a PGlite instance, loads the * pgvector extension, runs the schema DDL, and returns a ready * `{ backend, db }` pair whose `close()` disposes the engine. * * `@electric-sql/pglite` is an optional peer dependency. Vector support * additionally needs `@electric-sql/pglite-pgvector` (PGlite ≥ 0.5 ships * pgvector as a separate package). Install what you need: * * ```bash * pnpm add @electric-sql/pglite @electric-sql/pglite-pgvector * ``` * * @example In-memory database (default, vector enabled) * ```typescript * import { createLocalPgliteBackend } from "@nicia-ai/typegraph/adapters/drizzle/postgres/pglite"; * * const { backend } = await createLocalPgliteBackend(); * const store = createStore(graph, backend); * ``` * * @example Persistent on-disk database * ```typescript * const { backend, db } = await createLocalPgliteBackend({ dataDir: "./pgdata" }); * ``` * * @example No vector support (skip the pgvector extension) * ```typescript * const { backend } = await createLocalPgliteBackend({ vector: false }); * ``` * * PGlite is single-connection and serial: there is no pooling, so concurrent * `store.transaction()` calls queue rather than run in parallel. */ /** * Options for creating a local PGlite backend. */ type LocalPgliteBackendOptions = Readonly<{ /** * PGlite data directory. Omit for an in-memory database (the default). * Accepts any PGlite data-dir spec: a filesystem path (`"./pgdata"`), * `"memory://"`, or a browser/runtime-specific scheme such as * `"idb://my-db"`. */ dataDir?: string; /** * Custom table definitions. Defaults to standard TypeGraph table names. */ tables?: PostgresTables; /** * Controls the pgvector stack: * * - **omitted (default)** — load pgvector from `@electric-sql/pglite-pgvector` * and run `CREATE EXTENSION vector`, so embedding fields work out of the * box. Throws a {@link ConfigurationError} if the package isn't installed. * - **`false`** — skip the extension entirely; the backend advertises no * vector capability (mirroring a SQLite connection without sqlite-vec). * Use when a graph carries no embeddings, or to avoid the extension dep. * - **a PGlite `Extension`** — bring your own pgvector build or custom * extension packaging. Decouples this helper from a specific pgvector * package version. */ vector?: false | Extension; /** * Override the fulltext strategy. Defaults to `tsvectorStrategy`. Pass * `false` to disable fulltext support entirely — the backend then * advertises no `capabilities.fulltext` and omits the fulltext CRUD/search * methods, and the installation DDL never creates the fulltext table, * mirroring `vector: false`. */ fulltext?: FulltextStrategy | false; /** Opt in to provisioning within caller-owned schema transactions. */ schemaProvisioning?: SchemaProvisioning; }>; /** * Result of creating a local PGlite backend. */ type LocalPgliteBackendResult = Readonly<{ /** * The GraphBackend instance for use with createStore. Its `close()` * disposes the underlying PGlite engine. */ backend: AdapterBackend; /** * The underlying Drizzle database instance. Useful for direct SQL access. */ db: PgliteDatabase; /** * The raw PGlite instance, for engine-specific operations such as * `dumpDataDir()` / `clone()` not surfaced through Drizzle. */ client: PGlite; }>; /** * Creates a TypeGraph backend backed by an in-process PGlite database. * * Constructs the PGlite engine (loading pgvector unless disabled), executes * the schema DDL, and wires the standard Postgres backend. The returned * backend owns the engine: call `backend.close()` to dispose it. * * For production Postgres, or a PGlite instance you construct yourself, * use `createPostgresBackend` directly with your own Drizzle database — the * execution fast path detects PGlite and routes it correctly. * * @param options - Configuration options * @returns Backend, Drizzle database, and raw PGlite client */ declare function createLocalPgliteBackend(options?: LocalPgliteBackendOptions): Promise; export { AnyPgTransaction, type LocalPgliteBackendOptions, type LocalPgliteBackendResult, createLocalPgliteBackend };