feat(gateway): wire adapter factories + DI tokens alongside existing providers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
"@mosaic/log": "workspace:^",
|
||||
"@mosaic/memory": "workspace:^",
|
||||
"@mosaic/queue": "workspace:^",
|
||||
"@mosaic/storage": "workspace:^",
|
||||
"@mosaic/telegram-plugin": "workspace:^",
|
||||
"@mosaic/types": "workspace:^",
|
||||
"@nestjs/common": "^11.0.0",
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { Global, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
||||
import { createDb, type Db, type DbHandle } from '@mosaic/db';
|
||||
import { createStorageAdapter, type StorageAdapter } from '@mosaic/storage';
|
||||
|
||||
export const DB_HANDLE = 'DB_HANDLE';
|
||||
export const DB = 'DB';
|
||||
export const STORAGE_ADAPTER = 'STORAGE_ADAPTER';
|
||||
|
||||
const DEFAULT_DATABASE_URL = 'postgresql://mosaic:mosaic@localhost:5432/mosaic';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@@ -16,13 +20,24 @@ export const DB = 'DB';
|
||||
useFactory: (handle: DbHandle): Db => handle.db,
|
||||
inject: [DB_HANDLE],
|
||||
},
|
||||
{
|
||||
provide: STORAGE_ADAPTER,
|
||||
useFactory: (): StorageAdapter =>
|
||||
createStorageAdapter({
|
||||
type: 'postgres',
|
||||
url: process.env['DATABASE_URL'] ?? DEFAULT_DATABASE_URL,
|
||||
}),
|
||||
},
|
||||
],
|
||||
exports: [DB],
|
||||
exports: [DB, STORAGE_ADAPTER],
|
||||
})
|
||||
export class DatabaseModule implements OnApplicationShutdown {
|
||||
constructor(@Inject(DB_HANDLE) private readonly handle: DbHandle) {}
|
||||
constructor(
|
||||
@Inject(DB_HANDLE) private readonly handle: DbHandle,
|
||||
@Inject(STORAGE_ADAPTER) private readonly storageAdapter: StorageAdapter,
|
||||
) {}
|
||||
|
||||
async onApplicationShutdown(): Promise<void> {
|
||||
await this.handle.close();
|
||||
await Promise.all([this.handle.close(), this.storageAdapter.close()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { createMemory, type Memory } from '@mosaic/memory';
|
||||
import { createMemory, type Memory, createMemoryAdapter, type MemoryAdapter } from '@mosaic/memory';
|
||||
import type { Db } from '@mosaic/db';
|
||||
import { DB } from '../database/database.module.js';
|
||||
import { MEMORY } from './memory.tokens.js';
|
||||
import { MemoryController } from './memory.controller.js';
|
||||
import { EmbeddingService } from './embedding.service.js';
|
||||
|
||||
export const MEMORY_ADAPTER = 'MEMORY_ADAPTER';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [
|
||||
@@ -14,9 +16,13 @@ import { EmbeddingService } from './embedding.service.js';
|
||||
useFactory: (db: Db): Memory => createMemory(db),
|
||||
inject: [DB],
|
||||
},
|
||||
{
|
||||
provide: MEMORY_ADAPTER,
|
||||
useFactory: (): MemoryAdapter => createMemoryAdapter({ type: 'pgvector' }),
|
||||
},
|
||||
EmbeddingService,
|
||||
],
|
||||
controllers: [MemoryController],
|
||||
exports: [MEMORY, EmbeddingService],
|
||||
exports: [MEMORY, MEMORY_ADAPTER, EmbeddingService],
|
||||
})
|
||||
export class MemoryModule {}
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { createQueueAdapter, type QueueAdapter } from '@mosaic/queue';
|
||||
import { QueueService } from './queue.service.js';
|
||||
|
||||
export const QUEUE_ADAPTER = 'QUEUE_ADAPTER';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [QueueService],
|
||||
exports: [QueueService],
|
||||
providers: [
|
||||
QueueService,
|
||||
{
|
||||
provide: QUEUE_ADAPTER,
|
||||
useFactory: (): QueueAdapter =>
|
||||
createQueueAdapter({
|
||||
type: 'bullmq',
|
||||
url: process.env['VALKEY_URL'],
|
||||
}),
|
||||
},
|
||||
],
|
||||
exports: [QueueService, QUEUE_ADAPTER],
|
||||
})
|
||||
export class QueueModule {}
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -80,6 +80,9 @@ importers:
|
||||
'@mosaic/queue':
|
||||
specifier: workspace:^
|
||||
version: link:../../packages/queue
|
||||
'@mosaic/storage':
|
||||
specifier: workspace:^
|
||||
version: link:../../packages/storage
|
||||
'@mosaic/telegram-plugin':
|
||||
specifier: workspace:^
|
||||
version: link:../../plugins/telegram
|
||||
|
||||
Reference in New Issue
Block a user