UNPKG

@freemework/common

Version:

Common library of the Freemework Project.

44 lines 1.75 kB
import { FExecutionContext, FExecutionElement, FExecutionContextBase } from "../execution_context/f_execution_context.js"; export class FLoggerLabelsExecutionContext extends FExecutionContextBase { _loggerLabelValues; static of(executionContext) { const loggerCtx = FExecutionContext.findExecutionContext(executionContext, FLoggerLabelsExecutionContext); if (loggerCtx === null) { return null; } const chain = [loggerCtx]; const prevExecutionContext = loggerCtx.prevContext; if (prevExecutionContext != null) { chain.push(...FExecutionContext .listExecutionContexts(prevExecutionContext, FLoggerLabelsExecutionContext)); } return new FLoggerLabelsExecutionElement(loggerCtx, chain); } // TODO: make true-readonly set get loggerLabelValues() { return this._loggerLabelValues; } constructor(prevContext, ...loggerLabelValues) { super(prevContext); this._loggerLabelValues = Object.freeze([...loggerLabelValues]); } } export class FLoggerLabelsExecutionElement extends FExecutionElement { chain; constructor(owner, chain) { super(owner); this.chain = chain; } get loggerLabelValues() { // using reduceRight to take priority for first property in chain. const dict = this.chain.reduceRight((p, c) => { c.loggerLabelValues.forEach((lv) => { if (!p.has(lv.label)) { p.set(lv.label, lv); } }); return p; }, new Map); // TODO: make true-readonly set return [...dict.values()]; } } //# sourceMappingURL=f_logger_labels_execution_context.js.map