@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
42 lines • 1.67 kB
JavaScript
let sink = null;
/**
* Re-entrancy guard, mirroring `log-sink.ts`. `TelescopeService.record()`
* flushes through the Recorder into the configured `StorageProvider`; the
* MikroORM storage provider issues its OWN queries through a dedicated,
* isolated-`contextName` MikroORM instance (see
* `mikro-orm-storage.provider.ts`) — NOT the host's ORM that
* `telescopeMikroOrmLogger` is normally wired into. So in practice a
* `record()` call shouldn't loop back into `telescopeRecord()`. The guard is
* kept anyway — cheap, and it protects a host that (unusually) reuses the
* same ORM/logger for both app queries and Telescope's own storage from
* recursing into `record()` from inside `record()`.
* @internal
*/
let recordingInProgress = false;
/**
* Install (or clear, with `null`) the record sink. Called by
* `TelescopeService`'s lifecycle (constructor binds, shutdown clears) —
* hosts should not call this directly; it's also usable by tests/hosts that
* need to override the bound sink explicitly.
*/
export function setTelescopeRecordSink(fn) {
sink = fn;
}
/**
* Forward a boot-time record to the installed sink. A no-op — never throws,
* never buffers — until `TelescopeModule` has wired the sink (or after it's
* cleared on shutdown). Safe to call from anywhere, including code paths
* that run before Nest DI exists (ORM loggers, process hooks).
*/
export function telescopeRecord(input) {
if (sink === null || recordingInProgress)
return;
recordingInProgress = true;
try {
sink(input);
}
finally {
recordingInProgress = false;
}
}
//# sourceMappingURL=telescope-record.js.map