Files
TREK/server/src/nest/realtime/realtime-gateway.module.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

47 lines
2.3 KiB
TypeScript

import { AppSettings } from '../../db/entities/AppSettings.entity';
import { Trips } from '../../db/entities/Trips.entity';
import { Users } from '../../db/entities/Users.entity';
import { EphemeralTokenModule } from '../auth-core/ephemeral-token.module';
import { TripMembershipModule } from '../trip-membership/trip-membership.module';
import { RealtimeGateway } from './realtime.gateway';
import { processRooms, RoomRegistry, roomsSlot } from './ws-state';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module, type OnModuleDestroy } from '@nestjs/common';
/**
* The transport, kept out of RealtimeModule on purpose.
*
* RealtimeModule is @Global and every domain pulls it in for the broadcast
* facade. A gateway there would follow into every e2e TestingModule, and Nest's
* SocketModule loads a websocket adapter for any app that has one: with none
* set, it reaches for @nestjs/platform-socket.io and calls process.exit(1) when
* it is absent. Eighteen harnesses died that way.
*
* So this module is imported by AppModule alone. Test apps that assemble a few
* domain modules by hand get the facade without the transport, which is what
* they had before; the ones that boot the real buildApp() get both, with
* TrekWsAdapter already registered.
*/
@Module({
// The book rooms ask JOURNEY_ACCESS, bound globally by JourneyAccessModule
// to the same service the REST routes ask. Users/AppSettings: Plan 4 Task
// 1 — the handshake's password-version and require_mfa reads, moved off
// DatabaseService onto UsersRepository/AppSettingsRepository. Trips: Plan 4
// Task 2 — handleJoin's own canAccessTrip delegate, now TripsRepository
// directly.
imports: [TripMembershipModule, EphemeralTokenModule, MikroOrmModule.forFeature([Users, AppSettings, Trips])],
// The room registry is the process-wide in-memory one; the constructor
// below hands whichever one the container resolved to the broadcast
// functions, so the gateway and the broadcasts never use two registries.
providers: [RealtimeGateway, { provide: RoomRegistry, useValue: processRooms }],
})
export class RealtimeGatewayModule implements OnModuleDestroy {
constructor(private readonly rooms: RoomRegistry) {
roomsSlot.install(rooms);
}
onModuleDestroy(): void {
roomsSlot.release(this.rooms);
}
}