import * as valibot from 'valibot';
import { InferOutput } from 'valibot';

interface ExperimentalStreams {
    readonly serverUrl: string;
    readonly sqlitePath: string;
    readonly streamName: string;
    readonly url: string;
}
interface ExperimentalServerMetadata {
    readonly streams?: ExperimentalStreams;
}

declare const exportsSchema: valibot.ObjectSchema<{
    readonly database: valibot.ObjectSchema<{
        readonly connectionString: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
        readonly prismaORMConnectionString: valibot.OptionalSchema<valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>, undefined>;
        readonly terminalCommand: valibot.OptionalSchema<valibot.StringSchema<undefined>, undefined>;
    }, undefined>;
    readonly http: valibot.ObjectSchema<{
        readonly url: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
    }, undefined>;
    readonly ppg: valibot.ObjectSchema<{
        readonly url: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
    }, undefined>;
    readonly shadowDatabase: valibot.ObjectSchema<{
        readonly connectionString: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
        readonly prismaORMConnectionString: valibot.OptionalSchema<valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>, undefined>;
        readonly terminalCommand: valibot.OptionalSchema<valibot.StringSchema<undefined>, undefined>;
    }, undefined>;
}, undefined>;
type Exports = InferOutput<typeof exportsSchema>;
declare const serverDumpV1Schema: valibot.ObjectSchema<{
    readonly databasePort: valibot.SchemaWithPipe<readonly [valibot.NumberSchema<undefined>, valibot.IntegerAction<number, undefined>, valibot.MinValueAction<number, 1, undefined>]>;
    readonly experimental: valibot.OptionalSchema<valibot.ObjectSchema<{
        readonly streams: valibot.OptionalSchema<valibot.ObjectSchema<{
            readonly serverUrl: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
            readonly sqlitePath: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.MinLengthAction<string, 1, undefined>]>;
            readonly streamName: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.MinLengthAction<string, 1, undefined>]>;
            readonly url: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
        }, undefined>, undefined>;
    }, undefined>, undefined>;
    readonly exports: valibot.OptionalSchema<valibot.ObjectSchema<{
        readonly database: valibot.ObjectSchema<{
            readonly connectionString: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
            readonly prismaORMConnectionString: valibot.OptionalSchema<valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>, undefined>;
            readonly terminalCommand: valibot.OptionalSchema<valibot.StringSchema<undefined>, undefined>;
        }, undefined>;
        readonly http: valibot.ObjectSchema<{
            readonly url: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
        }, undefined>;
        readonly ppg: valibot.ObjectSchema<{
            readonly url: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
        }, undefined>;
        readonly shadowDatabase: valibot.ObjectSchema<{
            readonly connectionString: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>;
            readonly prismaORMConnectionString: valibot.OptionalSchema<valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.UrlAction<string, undefined>]>, undefined>;
            readonly terminalCommand: valibot.OptionalSchema<valibot.StringSchema<undefined>, undefined>;
        }, undefined>;
    }, undefined>, undefined>;
    readonly name: valibot.SchemaWithPipe<readonly [valibot.StringSchema<undefined>, valibot.MinLengthAction<string, 1, undefined>]>;
    readonly pid: valibot.OptionalSchema<valibot.SchemaWithPipe<readonly [valibot.NumberSchema<undefined>, valibot.IntegerAction<number, undefined>, valibot.MinValueAction<number, 0, undefined>]>, undefined>;
    readonly port: valibot.SchemaWithPipe<readonly [valibot.NumberSchema<undefined>, valibot.IntegerAction<number, undefined>, valibot.MinValueAction<number, 1, undefined>]>;
    readonly shadowDatabasePort: valibot.SchemaWithPipe<readonly [valibot.NumberSchema<undefined>, valibot.IntegerAction<number, undefined>, valibot.MinValueAction<number, 1, undefined>]>;
    readonly version: valibot.LiteralSchema<"1", undefined>;
}, undefined>;
type ServerDumpV1 = InferOutput<typeof serverDumpV1Schema>;
interface ServerOptions {
    /**
     * Connection timeout in milliseconds for pending database connections.
     *
     * This option is currently not enforced by the multiplexed
     * `@electric-sql/pglite-socket` server used by `@prisma/dev`.
     * It is kept for API compatibility until upstream exposes a queue-timeout
     * equivalent again.
     *
     * Default is 1 minute (60,000 milliseconds).
     */
    databaseConnectTimeoutMillis?: number;
    /**
     * Idle timeout in milliseconds for open database connections.
     *
     * Re-starts ticking after each message received on a connection. When exceeded,
     * that client connection is closed by the socket server.
     *
     * Is not applied by default.
     *
     * Use it with caution, as it may lead to unexpected disconnections. Best used
     * with a pool client that can handle disconnections gracefully.
     *
     * Set it if you suffer from client hanging indefinitely as the active connection
     * remain open forever.
     */
    databaseIdleTimeoutMillis?: number;
    /**
     * The port the database server will listen on.
     *
     * Defaults to `51214`.
     *
     * An error is thrown if the port is already in use.
     */
    databasePort?: number;
    /**
     * Whether to enable debug logging.
     *
     * Defaults to `false`.
     */
    debug?: boolean;
    /**
     * Whether to run the server in dry run mode.
     *
     * Defaults to `false`.
     */
    dryRun?: boolean;
    /**
     * The name of the server.
     *
     * Defaults to `default`.
     */
    name?: string;
    /**
     * The persistence mode of the server.
     *
     * Default is `stateless`.
     */
    persistenceMode?: PersistenceMode;
    /**
     * The port the server will listen on.
     *
     * Defaults to `51213`.
     *
     * An error is thrown if the port is already in use.
     */
    port?: number;
    /**
     * Connection timeout in milliseconds for pending shadow database connections.
     *
     * Default is {@link databaseConnectTimeoutMillis}.
     */
    shadowDatabaseConnectTimeoutMillis?: number;
    /**
     * Idle timeout in milliseconds for active shadow database connections.
     *
     * Default is {@link databaseIdleTimeoutMillis}.
     */
    shadowDatabaseIdleTimeoutMillis?: number;
    /**
     * The port the shadow database server will listen on.
     *
     * Defaults to `51215`.
     *
     * An error is thrown if the port is already in use.
     */
    shadowDatabasePort?: number;
    /**
     * The port the streams server will listen on.
     *
     * Defaults to `51216`.
     *
     * An error is thrown if the port is already in use.
     */
    streamsPort?: number;
}
type ResolvedServerOptions = Required<ServerOptions>;
type PersistenceMode = "stateless" | "stateful";
interface ScanOptions {
    debug?: boolean;
    globs?: string[];
    onlyMetadata?: boolean;
}
declare const PRIVATE_INITIALIZE_SYMBOL: unique symbol;
declare abstract class ServerState implements ResolvedServerOptions {
    #private;
    protected _databasePort: number;
    readonly databaseConnectTimeoutMillis: number;
    readonly databaseIdleTimeoutMillis: number;
    readonly debug: boolean;
    readonly dryRun: boolean;
    readonly name: string;
    readonly persistenceMode: PersistenceMode;
    readonly pid: number | undefined;
    readonly shadowDatabaseConnectTimeoutMillis: number;
    readonly shadowDatabaseIdleTimeoutMillis: number;
    protected _port: number;
    protected _shadowDatabasePort: number;
    protected _streamsPort: number;
    protected constructor(options: Omit<ServerOptions, "persistenceMode"> & {
        persistenceMode: PersistenceMode;
        pid?: number | undefined;
    });
    static createExclusively(options: ServerOptions | undefined): Promise<ServerState>;
    static fromServerDump(options?: Pick<ServerOptions, "debug" | "name">): Promise<StatefulServerState | null>;
    static scan(options?: ScanOptions): Promise<ServerStatusV1[]>;
    abstract get databaseDumpPath(): string;
    abstract get pgliteDataDirPath(): string;
    abstract [PRIVATE_INITIALIZE_SYMBOL](): Promise<void>;
    abstract close(): Promise<void>;
    abstract writeServerDump(exports?: Exports, experimental?: ExperimentalServerMetadata): Promise<void>;
    get databasePort(): number;
    set databasePort(value: number);
    get port(): number;
    set port(value: number);
    get shadowDatabasePort(): number;
    get streamsPort(): number;
    set shadowDatabasePort(value: number);
}
declare class StatefulServerState extends ServerState {
    #private;
    constructor(options: (Omit<ServerOptions, "persistenceMode"> & {
        pid?: number | undefined;
        serverDump?: ServerDumpV1;
    }) | undefined);
    static getServerDumpPath(dataDirPath: string): string;
    get databaseDumpPath(): string;
    get exports(): Exports | undefined;
    get experimental(): ExperimentalServerMetadata | undefined;
    get pgliteDataDirPath(): string;
    [PRIVATE_INITIALIZE_SYMBOL](): Promise<void>;
    close(): Promise<void>;
    writeServerDump(exports?: Exports, experimental?: ExperimentalServerMetadata): Promise<void>;
}
interface ServerStatusV1 extends ServerDumpV1 {
    status: "running" | "starting_up" | "not_running" | "no_such_server" | "unknown" | "error";
}
declare function deleteServer(nameOrStatus: string | ServerStatusV1, debug?: boolean): Promise<void>;
declare function getServerStatus(nameOrState: string | StatefulServerState, options?: ScanOptions): Promise<ServerStatusV1>;
declare function isServerRunning(server: ServerStatusV1): boolean;
declare function killServer(nameOrStatus: string | ServerStatusV1, debug?: boolean): Promise<boolean>;
/**
 * @deprecated use `ServerAlreadyRunningError` instead. Will be removed in a future version.
 */
declare class ServerStateAlreadyExistsError extends Error {
    name: string;
    constructor(name: string);
}
declare class ServerAlreadyRunningError extends ServerStateAlreadyExistsError {
    #private;
    name: string;
    constructor(server: ServerState);
    get server(): Promise<ServerState | null>;
}

export { type ExperimentalStreams as E, type PersistenceMode as P, type ResolvedServerOptions as R, type ServerOptions as S, type Exports as a, ServerAlreadyRunningError as b, ServerState as c, type ScanOptions as d, type ServerDumpV1 as e, ServerStateAlreadyExistsError as f, type ServerStatusV1 as g, deleteServer as h, getServerStatus as i, isServerRunning as j, killServer as k };
