import { i as SqlStatement, n as PostgresSqlConnection, t as EngineConnection } from "./sql-connection-DiMIHOpE.js";
import { r as DatabaseEngineInput } from "./types-SYtNBB5S.js";
import { a as StoreSchema, i as SearchStore, o as StoreSearchCapabilities, r as SearchSchema, t as AdmittedStore } from "./contract-BaQPdJAR.js";
import { t as getNodeSqliteKysely } from "./kysely-sync-Se3lLUms.js";
import "./config-6zrnU5pI.js";
import { DatabaseSync, SQLInputValue } from "node:sqlite";
import { Expression, RawBuilder, SqlBool } from "kysely";
import "kysely/helpers/sqlite";
//#region src/infra/database-engine/open.d.ts
/** Reuses the physical SQLite admission exchange across worker handles and idle reopen. */
declare function openEngineStore(ref: {
  anchor: DatabaseSync;
  schema: StoreSchema;
  input?: DatabaseEngineInput;
  openSqlite: () => void;
  prepareAnchor: () => void;
  inspectSqlite: () => {
    hasExistingData: boolean;
    hasEngineAnchor: boolean;
  };
  existingOnly?: boolean;
  /** Existing-state short leases may retain an idle PG transport in this worker. */
  reusePostgresConnection?: boolean;
  /** Inspection admits the declared source schema without running its migration. */
  existingVersion?: boolean;
  /** Bind owner-local state inside the new anchor transaction before connecting. */
  onFreshAnchor?: (anchor: DatabaseSync) => void;
  admitPostgres?: (db: PostgresSqlConnection, fresh: boolean) => void;
  beforeMigrate?: AdmittedStore["beforeMigrate"];
  /** Family custody for schema writes; shared state defaults to its physical owner. */
  assertMigrationCurrent?: () => void;
  closeOnFailure?: (db: PostgresSqlConnection, error: unknown) => never;
}): EngineConnection;
//#endregion
//#region src/infra/database-engine/admission-scope.d.ts
/** Temporarily admit synchronous boot and migration SQL on the Gateway main thread. */
declare function withEngineStoreAdmission<T>(operation: () => T): T;
//#endregion
//#region src/infra/database-engine/postgres-index-ordering.d.ts
type HistoricalOrdering = "sqlite" | "schema-nullability";
/** Restore a predecessor's index policy; generated table DDL owns column nullability. */
declare function withLegacyPostgresIndexOrdering(sql: string, policy?: HistoricalOrdering, schemaSql?: string): string;
/** The schema owner runs this under its existing versioned admission transaction. */
declare function postgresIndexOrderingMigration(sql: string, policy?: HistoricalOrdering): string;
//#endregion
//#region src/infra/postgres-sync/connection.d.ts
declare class PostgresSyncConnection implements PostgresSqlConnection {
  readonly schema: string;
  readonly anchor: DatabaseSync;
  readonly storeId: string;
  isOpen: boolean;
  isTransaction: boolean;
  mutationRevision: number;
  readonly advisoryLockKey: bigint;
  private bridge?;
  private idleCheckout;
  private lastResponseAt;
  private readonly bridgeParameters;
  private failure;
  private outcomeUnknown;
  private readOnlyTransaction;
  private pendingWrite;
  private readonly mainThread;
  private readonly reuseKey?;
  constructor(url: string, schema: string, anchor: DatabaseSync, storeId: string, options?: {
    lockTimeoutMs?: number;
    statementTimeoutMs?: number;
    reuse?: boolean;
  });
  private connect;
  runTransaction<T>(operation: () => T, options?: {
    withCommit?: (commit: () => void) => void;
  }, ...modes: [readOnly?: boolean, reserved?: boolean]): T;
  readRecoveryGeneration(lock?: boolean): string;
  private loseConnection;
  private finishWrite;
  private assertOpen;
  private request;
  query(sql: string, parameters?: readonly SQLInputValue[], readBigInts?: boolean): {
    rows: {
      [k: string]: import("node:sqlite").SQLOutputValue;
    }[];
    rowCount: number;
    columns: {
      name: string;
    }[];
  };
  private execute;
  exec(sql: string): void;
  prepare(sql: string): SqlStatement;
  /** Release only the idle backend; the logical reader keeps its admitted facts and anchor. */
  releaseIdleTransport(): void;
  close(): void;
}
//#endregion
//#region src/infra/database-engine/search-admission.d.ts
/** @experimental Admit an owner's extension, or bind its already admitted indexes. */
declare function admitStoreSearch(store: SearchStore, schema: SearchSchema, options?: {
  extension: string;
}): StoreSearchCapabilities;
//#endregion
//#region src/infra/database-engine/adapters.d.ts
/** Worker envelopes need a transaction only on PostgreSQL; native SQLite statements stay identical. */
declare function runEngineWorkerWrite<T>(input: DatabaseEngineInput, operation: () => T, transaction: (operation: () => T) => T): T;
declare function runEngineStoreReadSnapshot<T>(db: Parameters<typeof getNodeSqliteKysely>[0] | PostgresSyncConnection, operation: () => T): T;
//#endregion
//#region src/infra/database-engine/json-values.d.ts
declare function jsonPathValue<T = string | null>(db: DatabaseSync | PostgresSqlConnection, value: Expression<unknown>, path: Expression<string>, kind?: "text" | "number" | "json"): RawBuilder<T>;
//#endregion
export { postgresIndexOrderingMigration as a, openEngineStore as c, admitStoreSearch as i, runEngineStoreReadSnapshot as n, withLegacyPostgresIndexOrdering as o, runEngineWorkerWrite as r, withEngineStoreAdmission as s, jsonPathValue as t };