-
Notifications
You must be signed in to change notification settings - Fork 23
/
setup.util.ts
69 lines (58 loc) · 2.11 KB
/
setup.util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { Logger } from 'pino';
import { getAIModule, type AIModule } from '~/layers/ai/server/ai.module';
import { getAuthModule, type AuthModule } from '~/layers/auth/server/auth.module';
import { getGoogleModule, type GoogleModule } from '~/layers/google/server/google.module';
import { getHealthModule, type HealthModule } from '~/layers/health/server/health.module';
import { getImageModule, type ImageModule } from '~/layers/image/server/image.module';
import { getLoggerModule } from '~/layers/log/server/logger.module';
import { getMongoModule } from '~/layers/mongo/server/mongo.module';
import { getOpenAIModule } from '~/layers/openai/server/openai.module';
import { getPaletteModule, type PaletteModule } from '~/layers/palette/server/palette.module';
import { getUserModule, type UserModule } from '~/layers/user/server/user.module';
interface Modules {
ai: AIModule
logger: Logger
palette: PaletteModule
image: ImageModule
auth: AuthModule
user: UserModule
google: GoogleModule
health: HealthModule
}
export let modules: Modules;
export let isModulesReady = false;
export async function setup(): Promise<void> {
const logger = getLoggerModule();
try {
const mongodb = getMongoModule(logger);
logger.info('connecting to configured mongodb');
await mongodb.connect();
const db = mongodb.db();
logger.info('initializing modules and resolving dependencies');
const openai = getOpenAIModule(logger);
const ai = getAIModule(logger, openai.service);
const palette = getPaletteModule(db, logger, ai.service);
const image = getImageModule(logger, palette.service);
const user = getUserModule(db, logger);
const google = getGoogleModule(logger);
const auth = getAuthModule(logger, user.service, google.service);
const health = getHealthModule(db, logger);
await Promise.all([
palette.setup(),
user.setup()
]);
modules = {
ai,
logger,
palette,
image,
auth,
user,
google,
health
};
isModulesReady = true;
} catch (error) {
logger.warn({ err: error }, 'initializing setup failed');
}
}