Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

4.3 KB
Raw Blame
import { AppSettings } from '../../db/entities/AppSettings.entity';
import { StorageReclaimMarks } from '../../db/entities/StorageReclaimMarks.entity';
import { StorageReleaseQueue } from '../../db/entities/StorageReleaseQueue.entity';
import { AppConfigModule } from '../app-config/app-config.module';
import { AuditModule } from '../audit/audit.module';
import { DatabaseLifecycleModule } from '../database/database-lifecycle.module';
import { SchedulingModule } from '../scheduling/scheduling.module';
import { StorageAdminController } from './storage-admin.controller';
import { StorageAdminService } from './storage-admin.service';
import { StorageEventsService } from './storage-events.service';
import { StorageInstallService } from './storage-install.service';
import { StorageJobsService } from './storage-jobs.service';
import { StorageReclaimGuardService } from './storage-reclaim-guard.service';
import { StorageReclaimRegistryService } from './storage-reclaim-registry.service';
import { StorageReclaimController } from './storage-reclaim.controller';
import { StorageReclaimJob } from './storage-reclaim.job';
import { StorageReclaimService } from './storage-reclaim.service';
import { StorageRegistryService } from './storage-registry.service';
import { StorageReleaseJob } from './storage-release.job';
import { StorageReleaseService } from './storage-release.service';
import { StorageStatsService } from './storage-stats.service';
import { StorageUsageScanJob } from './storage-usage-scan.job';
import { StorageService } from './storage.service';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module } from '@nestjs/common';

/**
 * Storage container: registry (config), facade (byte-paths), admin surface.
 * AuditModule feeds the write audits. AuthModule is deliberately NOT imported
 * here — AuthModule itself imports StorageModule (avatar uploads), so the
 * reverse import is a real module cycle (Nest resolves it as `imports[1] is
 * undefined`, not a clean forwardRef case). JwtAuthGuard/AdminGuard need no
 * provider from AuthModule to begin with — they carry no constructor
 * dependencies, so `@UseGuards(JwtAuthGuard, AdminGuard)` instantiates them
 * directly, the same as BackupModule/BackupController (which also sits behind
 * StorageModule) already does. StorageRegistryService stays UNEXPORTED — the
 * admin controller reaches it as a same-module provider, and nothing outside
 * may cache drivers or trigger reloads. MikroOrmModule.forFeature registers
 * AppSettingsRepository for StorageRegistryService/StorageAdminService/
 * StorageStatsService's @InjectRepository (Plan 3i, storage task — SR/SA/SS's
 * 14 call sites, all on app_settings). The reclaim pass adds its marks table
 * and follows database reopens (DatabaseLifecycleModule); the domains whose
 * rows name stored objects register their reference sources with the exported
 * StorageReclaimRegistryService, so storage never imports them.
 * StorageJobsService is exported for the backups: a restore marks itself
 * running there and waits for a reclaim pass in flight to let go, a backup
 * marks itself so the pass deletes nothing it still reads.
 * StorageReleaseService is exported for the owners, which hand it the values a
 * delete or a replace left unnamed right after their write; it queues them,
 * and StorageReleaseJob deletes what is still unnamed once every undo window
 * has passed. StorageInstallService keeps this installation's id in the data
 * dir and resets the reclaim state of a database that came from elsewhere.
 */
@Module({
  imports: [
    AppConfigModule,
    AuditModule,
    DatabaseLifecycleModule,
    SchedulingModule,
    MikroOrmModule.forFeature([AppSettings, StorageReclaimMarks, StorageReleaseQueue]),
  ],
  controllers: [StorageAdminController, StorageReclaimController],
  providers: [
    StorageRegistryService,
    StorageService,
    StorageAdminService,
    StorageEventsService,
    StorageJobsService,
    StorageStatsService,
    StorageUsageScanJob,
    StorageReclaimRegistryService,
    StorageInstallService,
    StorageReclaimGuardService,
    StorageReclaimService,
    StorageReclaimJob,
    StorageReleaseService,
    StorageReleaseJob,
  ],
  exports: [
    StorageService,
    StorageEventsService,
    StorageJobsService,
    StorageReclaimRegistryService,
    StorageReleaseService,
  ],
})
export class StorageModule {}