pg-server
Version:
Postgres DB server emulator, proxy or honeypot
58 lines • 1.92 kB
TypeScript
/// <reference types="node" />
import { Server, Socket } from 'net';
import { DbRawCommand } from './server';
import { IProxiedServer } from './protocol/commands';
import { IResponseWriter } from './protocol/responses';
import { DbRawResponse } from './protocol/response-parser';
export type ProxyParties = {
/** The connected client */
client: IResponseWriter;
/** The proxied DB */
db: IProxiedServer;
};
type DbConnect = {
host: string;
port: number;
} | (() => Socket);
export interface InterceptedQuery {
query: string;
}
type CommandOrError = string | {
error: string;
};
export interface ISimpleProxySession {
/** Subscribe to new connections */
onConnect?(socket: Socket): any;
/** Handle inbound requests from connecting clients */
onQuery(query: string): CommandOrError | Promise<CommandOrError>;
}
export interface SimpleProxyCtor {
new (): ISimpleProxySession;
}
/**
* Create a db proxying server which only gives you a chance to intercepts/modify queries on the fly.
*
* This is a wrapper for @see createLowLevelProxy .
*
* Must call .listen() to start listening.
*/
export declare function createSimpleProxy(db: DbConnect, ctor: SimpleProxyCtor): Server;
export interface IAdvancedProxySession {
/** Subscribe to new connections */
onConnect?: (socket: Socket) => any;
/** Handle inbound requests from connecting clients. Must not throw any error. */
onCommand?: (command: DbRawCommand, parties: ProxyParties) => any;
/** Handle responses from the db */
onResult?: (result: DbRawResponse, parties: ProxyParties) => any;
}
export interface AdvancedProxyCtor {
new (): IAdvancedProxySession;
}
/**
* Create a db proxying server.
*
* Must call .listen() to start listening.
*/
export declare function createAdvancedProxy(db: DbConnect, ctor: AdvancedProxyCtor): Server;
export {};
//# sourceMappingURL=proxy.d.ts.map