added working config lib
This commit is contained in:
parent
f8576c0d93
commit
def9bce8dc
33 changed files with 2896 additions and 1485 deletions
75
libs/config/src/mongodb.ts
Normal file
75
libs/config/src/mongodb.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* MongoDB configuration using envalid
|
||||
* Document storage for sentiment data, raw documents, and unstructured data
|
||||
*/
|
||||
import { cleanEnv, str, port, bool, num } from 'envalid';
|
||||
|
||||
/**
|
||||
* MongoDB configuration with validation and defaults
|
||||
*/
|
||||
export const mongodbConfig = cleanEnv(process.env, {
|
||||
// MongoDB Connection
|
||||
MONGODB_HOST: str({ default: 'localhost', desc: 'MongoDB host' }),
|
||||
MONGODB_PORT: port({ default: 27017, desc: 'MongoDB port' }),
|
||||
MONGODB_DATABASE: str({ default: 'trading_documents', desc: 'MongoDB database name' }),
|
||||
|
||||
// Authentication
|
||||
MONGODB_USERNAME: str({ default: 'trading_admin', desc: 'MongoDB username' }),
|
||||
MONGODB_PASSWORD: str({ default: '', desc: 'MongoDB password' }),
|
||||
MONGODB_AUTH_SOURCE: str({ default: 'admin', desc: 'MongoDB authentication database' }),
|
||||
|
||||
// Connection URI (alternative to individual settings)
|
||||
MONGODB_URI: str({ default: '', desc: 'Complete MongoDB connection URI (overrides individual settings)' }),
|
||||
|
||||
// Connection Pool Settings
|
||||
MONGODB_MAX_POOL_SIZE: num({ default: 10, desc: 'Maximum connection pool size' }),
|
||||
MONGODB_MIN_POOL_SIZE: num({ default: 0, desc: 'Minimum connection pool size' }),
|
||||
MONGODB_MAX_IDLE_TIME: num({ default: 30000, desc: 'Maximum idle time for connections in ms' }),
|
||||
|
||||
// Timeouts
|
||||
MONGODB_CONNECT_TIMEOUT: num({ default: 10000, desc: 'Connection timeout in ms' }),
|
||||
MONGODB_SOCKET_TIMEOUT: num({ default: 30000, desc: 'Socket timeout in ms' }),
|
||||
MONGODB_SERVER_SELECTION_TIMEOUT: num({ default: 5000, desc: 'Server selection timeout in ms' }),
|
||||
|
||||
// SSL/TLS Settings
|
||||
MONGODB_TLS: bool({ default: false, desc: 'Enable TLS for MongoDB connection' }),
|
||||
MONGODB_TLS_INSECURE: bool({ default: false, desc: 'Allow invalid certificates in TLS mode' }),
|
||||
MONGODB_TLS_CA_FILE: str({ default: '', desc: 'Path to TLS CA certificate file' }),
|
||||
|
||||
// Additional Settings
|
||||
MONGODB_RETRY_WRITES: bool({ default: true, desc: 'Enable retryable writes' }),
|
||||
MONGODB_JOURNAL: bool({ default: true, desc: 'Enable write concern journal' }),
|
||||
MONGODB_READ_PREFERENCE: str({
|
||||
default: 'primary',
|
||||
choices: ['primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'],
|
||||
desc: 'MongoDB read preference'
|
||||
}),
|
||||
MONGODB_WRITE_CONCERN: str({ default: 'majority', desc: 'Write concern level' }),
|
||||
});
|
||||
|
||||
// Export typed configuration object
|
||||
export type MongoDbConfig = typeof mongodbConfig;
|
||||
|
||||
// Export individual config values for convenience
|
||||
export const {
|
||||
MONGODB_HOST,
|
||||
MONGODB_PORT,
|
||||
MONGODB_DATABASE,
|
||||
MONGODB_USERNAME,
|
||||
MONGODB_PASSWORD,
|
||||
MONGODB_AUTH_SOURCE,
|
||||
MONGODB_URI,
|
||||
MONGODB_MAX_POOL_SIZE,
|
||||
MONGODB_MIN_POOL_SIZE,
|
||||
MONGODB_MAX_IDLE_TIME,
|
||||
MONGODB_CONNECT_TIMEOUT,
|
||||
MONGODB_SOCKET_TIMEOUT,
|
||||
MONGODB_SERVER_SELECTION_TIMEOUT,
|
||||
MONGODB_TLS,
|
||||
MONGODB_TLS_INSECURE,
|
||||
MONGODB_TLS_CA_FILE,
|
||||
MONGODB_RETRY_WRITES,
|
||||
MONGODB_JOURNAL,
|
||||
MONGODB_READ_PREFERENCE,
|
||||
MONGODB_WRITE_CONCERN,
|
||||
} = mongodbConfig;
|
||||
Loading…
Add table
Add a link
Reference in a new issue