mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
b3a085df3f
The process-state ports were meant to let a store shared between processes replace the in-memory one, but they could not. The readers outside the container (the broadcast functions, the backup restore's permissions-cache flush, the pending-code sweep, hand-built consumers) went straight to the module-level in-memory instances, so an overridden provider was used by the gateway and the services while the broadcasts and the restore flush kept using the old store. And every port was synchronous, while a store in the database or on the network is async, so plugging one in would have changed every signature anyway. RateLimitStore, PendingCodeStore, OidcFlowStore and PermissionsCacheStore now return promises, and RateLimitService, OauthService, OidcService, PermissionsService and their callers await them. The in-memory stores still decide synchronously, so who gets a 429, a code or a cached level is unchanged. RoomRegistry stays synchronous: membership holds live sockets and broadcast() is a synchronous call every domain makes, so several processes need a fan-out in front of broadcast(), not a different place for the sets. The process-wide ports get a ProcessStoreSlot. PermissionsModule, OauthModule and RealtimeGatewayModule install the store the container resolved and release it on shutdown, and the free functions, the sweep and hand-built consumers read the slot, so overriding the provider changes every reader. Tests provide fake stores and check that the broadcasts, the restore flush and the sweep use them. Two callers needed more than an await. The transit MCP tools counted in a RateLimitService of their own that no provider could reach; they now take the one RateLimitModule provides (their mcp_transit_* buckets never overlap the REST ones). The link preview claimed its in-flight slot only after the budget check, which now yields, so simultaneous askers would each have been charged; it now claims the slot first, and an asker that joined someone out of budget asks again on its own budget. The unused putPendingCode/takePendingCode helpers are gone.
39 lines
1.8 KiB
TypeScript
39 lines
1.8 KiB
TypeScript
import { Module, type OnModuleDestroy } from '@nestjs/common';
|
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|
import { PermissionsService } from './permissions.service';
|
|
import { TripAccessGuard } from './trip-access.guard';
|
|
import { TripOwnerGuard } from './trip-owner.guard';
|
|
import { AppSettings } from '../../db/entities/AppSettings.entity';
|
|
import { PermissionsCacheStore, permissionsCacheSlot, processPermissionsCache } from './permissions-cache';
|
|
|
|
/** Cross-cutting permissions domain (Wave 2). No controller/MCP surface of its
|
|
* own — the admin HTTP surface stays with AdminModule. Exports
|
|
* PermissionsService for the 17 in-container consumers and TripAccessGuard/TripOwnerGuard
|
|
* for every trip-scoped controller; deliberately NOT @Global so e2e TestingModules
|
|
* resolve it transitively through each consumer's explicit import. Registered in
|
|
* AppModule. MikroOrmModule.forFeature registers AppSettingsRepository for
|
|
* PermissionsService's @InjectRepository — the two guards keep DatabaseService's
|
|
* canAccessTrip (Plan 3c), unaffected by this. */
|
|
@Module({
|
|
imports: [MikroOrmModule.forFeature([AppSettings])],
|
|
// The cache store is the process-wide in-memory one; a shared store replaces
|
|
// it here, and the constructor below hands whichever one the container
|
|
// resolved to the readers outside it (the backup restore's flush).
|
|
providers: [
|
|
PermissionsService,
|
|
TripAccessGuard,
|
|
TripOwnerGuard,
|
|
{ provide: PermissionsCacheStore, useValue: processPermissionsCache },
|
|
],
|
|
exports: [PermissionsService, TripAccessGuard, TripOwnerGuard],
|
|
})
|
|
export class PermissionsModule implements OnModuleDestroy {
|
|
constructor(private readonly cacheStore: PermissionsCacheStore) {
|
|
permissionsCacheSlot.install(cacheStore);
|
|
}
|
|
|
|
onModuleDestroy(): void {
|
|
permissionsCacheSlot.release(this.cacheStore);
|
|
}
|
|
}
|