@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
45 lines • 2.32 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
// packages/core/src/sse/stream.controller.ts
import { Controller, Inject, Sse, UseGuards } from '@nestjs/common';
import { merge, timer } from 'rxjs';
import { bufferTime, filter, map } from 'rxjs/operators';
import { TelescopeGuard } from '../nest/telescope.guard.js';
import { EntryEvents } from './entry-events.js';
let StreamController = class StreamController {
entryEvents;
constructor(entryEvents) {
this.entryEvents = entryEvents;
}
stream() {
// Coalesce bursts: collect type-batches over a 300ms window, emit one tick
// with the union of types. Skip empty windows.
const ticks = this.entryEvents.stream().pipe(bufferTime(300), filter((batches) => batches.length > 0), map((batches) => ({ data: { types: [...new Set(batches.flat())] } })));
const heartbeat = timer(15_000, 15_000).pipe(map(() => ({ data: { heartbeat: true } })));
return merge(ticks, heartbeat);
}
};
__decorate([
Sse('stream'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Function)
], StreamController.prototype, "stream", null);
StreamController = __decorate([
UseGuards(TelescopeGuard),
Controller(),
__param(0, Inject(EntryEvents)),
__metadata("design:paramtypes", [EntryEvents])
], StreamController);
export { StreamController };
//# sourceMappingURL=stream.controller.js.map