import { Pool } from 'pg'; /** * A dictionary of string keys and generic values. Consider using it instead of `any`. */ export interface Dict { [key: string]: T; } /** * An interface that represents a logger implementation to be used by components of `@axinom/mosaic-db-common`. An example of Mosaic implementation: * ```ts * import { Logger } from '@axinom/mosaic-service-common'; * //... * const logger = new Logger({ context: 'messaging' }); * ``` */ export interface DbLogger { trace(message: string): void; debug(message: string): void; debug(error: Error): void; error(message: string): void; error(error: Error): void; error(error: Error, message: string): void; log(message: string): void; warn(message: string): void; } /** * An interface that represents a middleware object to be used to register messaging actions that are executed on app shutdown, e.g. PostgreSQL pool shutdown. * An example of Mosaic implementation: * ```ts * import { setupShutdownActions, Logger } from '@axinom/mosaic-service-common'; * //... * const shutdownActions = setupShutdownActions(app, logger); * ``` */ export interface DbShutdownActions { push(action: () => void | Promise): void; } /** * An abstract type extending PostgreSQL Pool. All labelled pool types extend * pg.Pool but labelled pool types are not interchangeable so typescript can be * leveraged to ensure the correct pool type is being used in a given context. */ export type LabelledPgPool = Pool & { label: T }; /** * Default labelled pool types */ export type OwnerPgPool = LabelledPgPool<'Owner'>; export type EnvOwnerPgPool = LabelledPgPool<'EnvOwner'>; export type LoginPgPool = LabelledPgPool<'Login'>;