UNPKG

@data-loom/postgrest-js

Version:

Isomorphic PostgREST client

57 lines 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.traceIdGenerator = exports.TraceIdGenerator = void 0; /** * TraceIdGenerator * * A singleton class for generating auto-incrementing trace IDs within a process. * Each call to next() returns a unique, incremented number. * * @example * const traceId = traceIdGenerator.next(); */ class TraceIdGenerator { constructor() { /** * The current trace id value. */ this.counter = 1; } /** * Get the singleton instance of TraceIdGenerator. * @returns {TraceIdGenerator} */ static getInstance() { if (!TraceIdGenerator.instance) { TraceIdGenerator.instance = new TraceIdGenerator(); } return TraceIdGenerator.instance; } /** * Get the next trace id (auto-increment). * @returns {number} The next trace id. */ next() { return this.counter++; } /** * Get the current trace id (without increment). * @returns {number} The current trace id. */ getCurrent() { return this.counter; } /** * Reset the trace id counter to 1. (For testing or special use only) */ reset() { this.counter = 1; } } exports.TraceIdGenerator = TraceIdGenerator; /** * The singleton instance for trace id generation. */ const traceIdGenerator = TraceIdGenerator.getInstance(); exports.traceIdGenerator = traceIdGenerator; //# sourceMappingURL=trace-id.js.map