import { ExtractTablesWithRelations, SQLWrapper } from "drizzle-orm";
import { PgDatabase, PgQueryResultHKT, PgTransaction, PgTransactionConfig } from "drizzle-orm/pg-core";
//#region src/transaction.d.ts
type TransactionIdentity = {
  readonly $platformTransactionIdentity: 'v1';
};
/** Structural phantom marker; runtime authenticity is callback-scoped. */
type TransactionCapability<S = unknown> = {
  readonly $platformTransaction: {
    readonly schema: S;
  };
};
declare class TransactionCapabilityError extends Error {
  readonly reason: 'inactive' | 'identity-mismatch';
  readonly code = "transaction-capability";
  constructor(reason: 'inactive' | 'identity-mismatch');
}
declare function isTransactionCapabilityError(error: unknown): error is TransactionCapabilityError;
declare function getTransactionIdentity(tx: TransactionCapability): TransactionIdentity;
declare function assertTransactionIdentity(tx: TransactionCapability, expectedIdentity: TransactionIdentity): void;
/**
 * Brands a driver-built handle so its transactions carry platform transaction identity. First-party
 * adapters apply it for you. It is public because a consumer that constructs its own driver client — a
 * real-Postgres test harness, or any driver with no first-party adapter — otherwise cannot produce a
 * value satisfying `TransactionalDatabase`, and reaching into `db/src` for it breaks the moment the
 * package is consumed as published `dist`.
 */
declare function withTransactionIdentity<T extends object>(database: T): T;
//#endregion
//#region src/index.d.ts
/** The host's drizzle schema (pgTables + relations). db core defines none — it is generic over this. */
type Schema = Record<string, unknown>;
/** Query-capable handle WITHOUT interactive transactions. What `./postgres/neon-http` returns. */
type Database<S extends Schema = Record<string, never>> = Omit<PgDatabase<PgQueryResultHKT, S, ExtractTablesWithRelations<S>>, 'transaction'>;
/** Dialect-neutral callback-only mutation handle. */
type Transaction<S extends Schema = Record<string, never>> = TransactionCapability<S> & {
  execute<Row extends Record<string, unknown> = Record<string, unknown>>(query: SQLWrapper): Promise<readonly Row[]>;
};
type PgTransactionHandle<S extends Schema> = Pick<PgTransaction<PgQueryResultHKT, S, ExtractTablesWithRelations<S>>, 'query' | '$with' | '$count' | 'with' | 'select' | 'selectDistinct' | 'selectDistinctOn' | 'update' | 'insert' | 'delete' | 'refreshMaterializedView'>;
/** Strongly typed PostgreSQL handle supplied by PostgreSQL adapter callbacks. */
type PostgresTransaction<S extends Schema = Record<string, never>> = PgTransactionHandle<S> & Transaction<S> & {
  transaction<T>(fn: (tx: PostgresTransaction<S>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
};
/** Adds interactive transactions back. What `./postgres/neon-serverless`, `./postgres/postgres-js`, `./postgres/pglite` return. */
type TransactionalDatabase<S extends Schema = Record<string, never>> = Database<S> & {
  transaction<T>(fn: (tx: PostgresTransaction<S>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
};
/** The workhorse PostgreSQL query handle, in or out of a transaction. */
type Querier<S extends Schema = Record<string, never>> = Database<S> | PostgresTransaction<S>;
/** Dialect identifier for adapter selection */
type Dialect = 'postgres' | 'sqlite';
//#endregion
export { Schema as a, TransactionCapabilityError as c, getTransactionIdentity as d, isTransactionCapabilityError as f, Querier as i, TransactionIdentity as l, Dialect as n, Transaction as o, withTransactionIdentity as p, PostgresTransaction as r, TransactionalDatabase as s, Database as t, assertTransactionIdentity as u };