mvom
Version:
Multivalue Object Mapper
117 lines (116 loc) • 5.12 kB
TypeScript
import type http from 'http';
import type https from 'https';
import { type ModelConstructor } from './compileModel';
import type { DeployOptions } from './DeploymentManager';
import type { Logger } from './LogHandler';
import type Schema from './Schema';
import type { DbServerLimits, DbSubroutineInputOptionsMap, DbSubroutineResponseTypesMap, DbSubroutineSetupOptions, ISOCalendarDate, ISOCalendarDateTime, ISOTime } from './types';
export interface CreateConnectionOptions {
/** Optional logger instance */
logger?: Logger;
/**
* Lifetime of cache of db server data (s)
* @defaultValue 3600
*/
cacheMaxAge?: number;
/**
* Request timeout (ms)
* 0 implies no timeout
* @defaultValue 0
*/
timeout?: number;
/** Optional http agent */
httpAgent?: http.Agent;
/** Optional https agent */
httpsAgent?: https.Agent;
/** Maximum allowed return payload size in bytes */
maxReturnPayloadSize?: number;
}
export declare enum ConnectionStatus {
disconnected = "disconnected",
connected = "connected",
connecting = "connecting"
}
interface RequestOptions {
requestId?: string;
}
export interface OpenOptions extends RequestOptions {
/**
* Validate the multivalue subroutine deployment before opening the connection
* @defaultValue `true`
*/
validateDeployment?: boolean;
}
export type DbServerInfoOptions = RequestOptions;
export type GetDbDateOptions = RequestOptions;
export type GetDbDateTimeOptions = RequestOptions;
export type GetDbTimeOptions = RequestOptions;
export type GetDbLimitsOptions = RequestOptions;
/** A connection object */
declare class Connection {
/** Connection status */
status: ConnectionStatus;
/** Log handler instance used for diagnostic logging */
private readonly logHandler;
/** Maximum age of the cache before it must be refreshed */
private readonly cacheMaxAge;
/** Multivalue database server information */
private dbServerInfo?;
/** Axios instance */
private readonly axiosInstance;
/** Deployment Manager instance */
private readonly deploymentManager;
/** Mutex on acquiring server information */
private readonly serverInfoMutex;
/** Maximum allowed return payload size in bytes */
private readonly maxReturnPayloadSize;
private constructor();
/** Returns the subroutine name that is used on the multivalue server */
get subroutineName(): string;
/** Create a connection */
static createConnection(
/** URL of the MVIS which facilitates access to the mv database */
mvisUrl: string,
/** URL of the MVIS Admin */
mvisAdminUrl: string,
/** MVIS Admin Username */
mvisAdminUsername: string,
/** MVIS Admin Password */
mvisAdminPassword: string,
/** Database account that connection will be used against */
account: string, options?: CreateConnectionOptions): Connection;
/** Open a database connection */
open(options?: OpenOptions): Promise<void>;
/** Deploy source code to MVIS & db server */
deploy(sourceDir: string, options?: DeployOptions): Promise<void>;
/** Execute a database subroutine */
executeDbSubroutine<TSubroutineName extends keyof (DbSubroutineInputOptionsMap & DbSubroutineResponseTypesMap)>(subroutineName: TSubroutineName, options: DbSubroutineInputOptionsMap[TSubroutineName], setupOptions?: DbSubroutineSetupOptions, teardownOptions?: Record<string, never>): Promise<DbSubroutineResponseTypesMap[TSubroutineName]['output']>;
/** Get the current ISOCalendarDate from the database */
getDbDate({ requestId }?: GetDbDateOptions): Promise<ISOCalendarDate>;
/** Get the current ISOCalendarDateTime from the database */
getDbDateTime({ requestId, }?: GetDbDateTimeOptions): Promise<ISOCalendarDateTime>;
/** Get the current ISOTime from the database */
getDbTime({ requestId }?: GetDbTimeOptions): Promise<ISOTime>;
/** Get the multivalue database server limits */
getDbLimits({ requestId }?: GetDbLimitsOptions): Promise<DbServerLimits>;
/** Define a new model */
model<TSchema extends Schema | null>(schema: TSchema, file: string): ModelConstructor<TSchema>;
/** Validate the multivalue subroutine deployment */
private validateDeployment;
/** Get the db server information (date, time, etc.) */
private getDbServerInfo;
/**
* Handle error from the database server
* @throws {@link ForeignKeyValidationError} A foreign key constraint was violated
* @throws {@link RecordLockedError} A record was locked and could not be updated
* @throws {@link RecordVersionError} A record changed between being read and written and could not be updated
* @throws {@link DbServerError} An error was encountered on the database server
* @throws {@link RecordNotFoundError} A record was not found and could not be updated
*/
private handleDbServerError;
/** Handle an axios error */
private handleAxiosError;
/** Handle an unknown error */
private handleUnexpectedError;
}
export default Connection;