|
| 1 | +import { Module } from '@nestjs/common'; |
| 2 | +import { AgentCreateQuestions, AgentsCommand } from './agents.command'; |
| 3 | +import { ConfigModule, ConfigService } from '@nestjs/config'; |
| 4 | +import { BullModule } from '@nestjs/bullmq'; |
| 5 | +import { RedisOptions } from 'ioredis'; |
| 6 | +import { RedisModule } from '@nestjs-modules/ioredis'; |
| 7 | +import { MongooseModule, MongooseModuleOptions } from '@nestjs/mongoose'; |
| 8 | +import mongoose from 'mongoose'; |
| 9 | +import config, { MongoosePlugin } from '~/config'; |
| 10 | +import { AgentsModule } from '~/core/agents/agents.module'; |
| 11 | +import { KeyringsCommand, KeyringsCreateQuestions } from './keyrings.command'; |
| 12 | +import { KeyringsModule } from '~/core/keyrings/keyrings.module'; |
| 13 | + |
| 14 | +@Module({ |
| 15 | + imports: [ |
| 16 | + ConfigModule.forRoot({ |
| 17 | + isGlobal: true, |
| 18 | + load: [config], |
| 19 | + }), |
| 20 | + MongooseModule.forRootAsync({ |
| 21 | + imports: [ConfigModule], |
| 22 | + inject: [ConfigService], |
| 23 | + useFactory: async (config: ConfigService) => { |
| 24 | + for (const plugin of config.get<MongoosePlugin[]>('mongoose.plugins')) { |
| 25 | + import(plugin.package).then((plugin) => { |
| 26 | + mongoose.plugin(plugin.default ? plugin.default : plugin, plugin.options); |
| 27 | + }); |
| 28 | + } |
| 29 | + return { |
| 30 | + ...config.get<MongooseModuleOptions>('mongoose.options'), |
| 31 | + uri: config.get<string>('mongoose.uri'), |
| 32 | + }; |
| 33 | + }, |
| 34 | + }), |
| 35 | + RedisModule.forRootAsync({ |
| 36 | + imports: [ConfigModule], |
| 37 | + inject: [ConfigService], |
| 38 | + useFactory: async (config: ConfigService) => ({ |
| 39 | + config: { |
| 40 | + ...config.get<RedisOptions>('ioredis.options'), |
| 41 | + url: config.get<string>('ioredis.uri'), |
| 42 | + }, |
| 43 | + }), |
| 44 | + }), |
| 45 | + BullModule.forRootAsync({ |
| 46 | + imports: [ConfigModule], |
| 47 | + inject: [ConfigService], |
| 48 | + useFactory: async (configService: ConfigService) => ({ |
| 49 | + connection: { |
| 50 | + host: configService.get('ioredis.host'), |
| 51 | + port: configService.get('ioredis.port'), |
| 52 | + }, |
| 53 | + }), |
| 54 | + }), |
| 55 | + AgentsModule, |
| 56 | + KeyringsModule, |
| 57 | + ], |
| 58 | + providers: [ |
| 59 | + ...AgentsCommand.registerWithSubCommands(), |
| 60 | + ...KeyringsCommand.registerWithSubCommands(), |
| 61 | + AgentCreateQuestions, |
| 62 | + KeyringsCreateQuestions, |
| 63 | + ], |
| 64 | +}) |
| 65 | +export class CliModule {} |
0 commit comments