import IBackend from '../contracts/IBackend'; import ISessionBackend from '../contracts/ISessionBackend'; import IClientContext from '../contracts/IClientContext'; import { ConnectionOptions, OpenSessionRequest } from '../contracts/IDBSQLClient'; import { KernelNativeBinding } from './KernelNativeLoader'; export interface KernelBackendOptions { /** * Required. Provides the logger + config the kernel session/operation chain * logs through. `DBSQLClient` supplies it via the kernel seam * (`new KernelBackend({ context: this })`); unit tests pass a stub. Kept * mandatory (rather than an `as IClientContext` downcast of `undefined`) * so a missing context is a compile error, not a latent runtime NPE. */ context: IClientContext; /** * Optional injection seam for unit tests. When provided, replaces the * default `getKernelNative()` call so tests can swap in a mock napi * binding without loading the `.node` artifact. */ nativeBinding?: KernelNativeBinding; } /** * kernel-backed implementation of `IBackend`. * * **M0 dispatch model:** the napi binding's `openSession()` already * builds a kernel `Session` from PAT + hostname + httpPath, so there is * no "connect" round-trip before `openSession` — `connect()` only * captures the `ConnectionOptions` and validates that PAT auth is in * use. The actual session open happens inside `openSession()`. * * **Auth validation:** delegates to `buildKernelConnectionOptions` from * `KernelAuth`, which mirrors the existing DBSQLClient validation pattern * (slash-prepended httpPath, AuthenticationError on missing token or * blank OAuth credentials, HiveDriverError on unsupported authType / * Azure-direct / ambiguous credential combinations). M2M and U2M * routing key off `oauthClientId` presence; see KernelAuth.ts. * * **Why we don't use IClientContext's connectionProvider here:** that * provider is the Thrift HTTP transport. The kernel owns its own * reqwest+rustls stack inside the native binding, so there is no * NodeJS-level connection state to manage on the kernel path. The * `IClientContext` is still useful for logger + config access. */ export default class KernelBackend implements IBackend { private readonly context; private readonly binding; private nativeOptions?; private kernelLogUnsubscribe; constructor(options: KernelBackendOptions); connect(options: ConnectionOptions): Promise; openSession(request: OpenSessionRequest): Promise; close(): Promise; }