import { Database } from './Database.js' import { DATABASES } from './DatabaseManager.js' import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js' import { KnexDatabase } from './integrations/knex/KnexDatabase.js' import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js' import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js' /** * Represents the possible types of databases available in the system. * @typedef {keyof typeof DATABASES} DatabaseType */ export type DatabaseType = keyof typeof DATABASES /** * Defines a type for a database class that includes instances for Knex, Postgres, and Kysely databases. * @template T - The type of data the KyselyDatabase instance will handle. * @property {new (...args: any[]) => KnexDatabase} knex - Constructor for KnexDatabase instances. * @property {new (...args: any[]) => PostgresDatabase} pg - Constructor for PostgresDatabase instances. * @property {new (...args: any[]) => KyselyDatabase} kysely - Constructor for KyselyDatabase instances with type T. */ export type DatabaseClass = { knex: new (...args: any[]) => KnexDatabase pg: new (...args: any[]) => PostgresDatabase kysely: new (...args: any[]) => KyselyDatabase dynamo: new (...args: any[]) => DynamoDatabase } /** * Represents a specific implementation type for a database based on the provided DatabaseType. * @param {DatabaseType} Type - The type of database to implement. * @param {T} T - The generic type for the database implementation. * @returns An instance of the specified database class for the given type. */ export type DatabaseImplType = InstanceType[Type]> /** * Defines the type of transaction for a specific database type and schema. * @param {DatabaseType} Type - The type of the database. * @param {DBSchema} DBSchema - The schema of the database. * @returns The transaction type associated with the database type and schema. */ export type DatabaseTransactionType = DatabaseImplType extends Database ? TransactionType : never /** * Defines the configuration options for different types of databases. * @typedef {Object} DbBaseConfig * @property {string} host - The host of the database. * @property {number} port - The port number of the database. * @property {string} username - The username for accessing the database. * @property {string} password - The password for accessing the database. * @property {string} database - The name of the database. * @property {boolean} autoCommit - Flag indicating whether auto-commit is enabled. * @property {number} maxConnections - The maximum number of connections allowed. * * @typedef {Object} DbConfig * @property {string} type - The type of */ export type DbBaseConfig = { host: string port: number username: string password: string database: string autoCommit: boolean maxConnections: number } /** * Defines the configuration options for different types of databases. * @template S - The type of database (e.g., 'knex', 'pg', 'kysely') * @typedef {Object} DbConfig * @property {DbBaseConfig} DbBaseConfig - The base configuration for the database. * @property {S} type - The type of the database. * @property {string} [driver] - The driver for the 'knex' database type. * @property {boolean} [convertCamelToSnake] - Whether to convert camel case to snake case for 'knex' database type. * @property {DbBaseConfig} [readReplica] - The read replica configuration for ' */ export type DbConfig = { type: S } & (S extends 'knex' ? DbBaseConfig & { driver?: string convertCamelToSnake?: boolean } : unknown) & (S extends 'pg' | 'kysely' ? DbBaseConfig & { readReplica?: DbBaseConfig } : unknown) & (S extends 'dynamo' ? { region: string tableName: string maxAttempts?: number connectionTimeout?: number } : unknown)