import { Client } from '@libsql/client'; import { LibSQLDatabase } from 'drizzle-orm/libsql'; import { S as SchemaProvisioning, A as AdapterBackend } from '../../types-BynPp5kU.js'; export { C as ContributionDiagnostic, a as ContributionDiagnosticState, b as ContributionRepairEntry, c as ContributionRepairResult, G as GraphIdentityConfig } from '../../types-BynPp5kU.js'; import { A as AnySqliteDatabase } from '../../sqlite-execution-DHenxnsc.js'; import { a as SqliteTables } from '../../sqlite-CcCSeXGg.js'; import 'zod'; import 'drizzle-orm/sqlite-core'; /** * libsql backend for TypeGraph. * * This module wraps `@libsql/client` with the correct execution profile * for use with TypeGraph. It is compatible with any `@libsql/client` * instance (local file, remote Turso, embedded replicas). * * @example In-memory database * ```typescript * import { createClient } from "@libsql/client"; * import { createLibsqlBackend } from "@nicia-ai/typegraph/adapters/drizzle/sqlite/libsql"; * * const client = createClient({ url: "file::memory:" }); * const { backend } = await createLibsqlBackend(client); * const store = createStore(graph, backend); * ``` * * @example Remote Turso database * ```typescript * import { createClient } from "@libsql/client"; * import { createLibsqlBackend } from "@nicia-ai/typegraph/adapters/drizzle/sqlite/libsql"; * * const client = createClient({ url: "libsql://my-db.turso.io", authToken: "..." }); * const { backend } = await createLibsqlBackend(client); * const store = createStore(graph, backend); * ``` */ /** * Options for creating a libsql backend. */ type LibsqlBackendOptions = Readonly<{ schemaProvisioning?: SchemaProvisioning; /** * Custom table definitions. * Defaults to standard TypeGraph table names. */ tables?: SqliteTables; }>; /** * Result of creating a libsql backend. */ type LibsqlBackendResult = Readonly<{ /** * The GraphBackend instance for use with createStore. */ backend: AdapterBackend; /** * The underlying Drizzle database instance. * Useful for direct SQL access or sharing the connection. */ db: LibSQLDatabase; }>; /** * Creates a TypeGraph backend backed by `@libsql/client`. * * Handles DDL execution and configures the correct execution profile. * Local clients (`client.protocol === "file"`, covering `file:` paths and * `:memory:` databases — see `isLocalLibsqlClient`) run transactions as raw * BEGIN/COMMIT statements on the client's single stable connection * (`transactionMode: "sql"`): `client.transaction()` permanently hands that * connection to the transaction and lazily opens a fresh one afterwards, which * for an in-memory database is a fresh, empty database. Remote clients (`http` / * `ws`) run each transaction on its own stream via Drizzle's * `db.transaction()` (`transactionMode: "drizzle"`). The caller retains * ownership of the client and is responsible for closing it. * * Because that single local connection is also what makes a snapshot export and * a concurrent write mutually exclusive, `createSqliteBackend` marks the backend * with a local client as its serialized transaction resource — so two backends * over ONE local client are recognized as one connection by the streaming * import guard and the working-copy cloner. Remote clients are deliberately not * marked. * * @param client - An `@libsql/client` Client instance * @param options - Configuration options * @returns Backend and Drizzle database instances * * @example * ```typescript * import { createClient } from "@libsql/client"; * import { createLibsqlBackend } from "@nicia-ai/typegraph/adapters/drizzle/sqlite/libsql"; * * const client = createClient({ url: "file::memory:" }); * const { backend } = await createLibsqlBackend(client); * ``` */ declare function createLibsqlBackend(client: Client, options?: LibsqlBackendOptions): Promise; export { AnySqliteDatabase, type LibsqlBackendOptions, type LibsqlBackendResult, createLibsqlBackend };