feat(rustbridge): add RustBridge and RustBinaryLocator with typed IPC interfaces, plugins, tests and mock runner; export from index; add npm registries

This commit is contained in:
2026-02-10 09:10:18 +00:00
parent fad0b9e602
commit 40dec91940
14 changed files with 865 additions and 12 deletions

42
ts/interfaces/config.ts Normal file
View File

@@ -0,0 +1,42 @@
/**
* Minimal logger interface for the bridge.
*/
export interface IRustBridgeLogger {
log(level: string, message: string, data?: Record<string, any>): void;
}
/**
* Options for locating a Rust binary.
*/
export interface IBinaryLocatorOptions {
/** Name of the binary (e.g., 'rustproxy') */
binaryName: string;
/** Environment variable to check for explicit binary path (e.g., 'SMARTPROXY_RUST_BINARY') */
envVarName?: string;
/** Prefix for platform-specific npm packages (e.g., '@push.rocks/smartproxy') */
platformPackagePrefix?: string;
/** Additional local paths to search (defaults to ./rust/target/release/<binaryName> and ./rust/target/debug/<binaryName>) */
localPaths?: string[];
/** Whether to search the system PATH (default: true) */
searchSystemPath?: boolean;
/** Explicit binary path override - skips all other search */
binaryPath?: string;
}
/**
* Options for the RustBridge.
*/
export interface IRustBridgeOptions extends IBinaryLocatorOptions {
/** CLI arguments passed to the binary (default: ['--management']) */
cliArgs?: string[];
/** Timeout for individual requests in ms (default: 30000) */
requestTimeoutMs?: number;
/** Timeout for the ready event during spawn in ms (default: 10000) */
readyTimeoutMs?: number;
/** Additional environment variables for the child process */
env?: Record<string, string>;
/** Name of the ready event emitted by the Rust binary (default: 'ready') */
readyEventName?: string;
/** Optional logger instance */
logger?: IRustBridgeLogger;
}

2
ts/interfaces/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './ipc.js';
export * from './config.js';

40
ts/interfaces/ipc.ts Normal file
View File

@@ -0,0 +1,40 @@
/**
* Management request sent to the Rust binary via stdin.
*/
export interface IManagementRequest {
id: string;
method: string;
params: Record<string, any>;
}
/**
* Management response received from the Rust binary via stdout.
*/
export interface IManagementResponse {
id: string;
success: boolean;
result?: any;
error?: string;
}
/**
* Management event received from the Rust binary (unsolicited, no id field).
*/
export interface IManagementEvent {
event: string;
data: any;
}
/**
* Definition of a single command supported by a Rust binary.
*/
export interface ICommandDefinition<TParams = any, TResult = any> {
params: TParams;
result: TResult;
}
/**
* Map of command names to their definitions.
* Used to type-safe the bridge's sendCommand method.
*/
export type TCommandMap = Record<string, ICommandDefinition>;