UNPKG

@dudousxd/nestjs-telescope

Version:

Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.

31 lines 1.04 kB
// packages/core/src/context/telescope-context.ts import { AsyncLocalStorage } from 'node:async_hooks'; export class TelescopeContext { als = new AsyncLocalStorage(); run(batch, fn) { return this.als.run({ batch, sequence: 0 }, fn); } /** * Establish `batch` as the active batch for the current async execution and * all its descendants, WITHOUT a callback scope. Used by the request * middleware so the batch survives the middleware return and reaches the * async handler and exception interceptor. */ enterWith(batch) { this.als.enterWith({ batch, sequence: 0 }); } current() { return this.als.getStore()?.batch; } /** Next capture-order index within the active batch; 0 outside any batch. */ nextSequence() { const state = this.als.getStore(); if (!state) { return 0; } const next = state.sequence; state.sequence += 1; return next; } } //# sourceMappingURL=telescope-context.js.map