{"version":3,"sources":["/home/runner/work/loglayer/loglayer/packages/core/context-manager/dist/index.cjs","../src/DefaultContextManager.ts","../src/MockContextManager.ts"],"names":[],"mappings":"AAAA;ACQO,IAAM,sBAAA,YAAN,MAAM,uBAAiD;AAAA,iBACpD,QAAA,EAA+B,CAAC,EAAA;AAAA,kBAChC,WAAA,EAAa,MAAA;AAAA;AAAA;AAAA;AAAA,EAKrB,UAAA,CAAW,OAAA,EAAqC;AAC9C,IAAA,GAAA,CAAI,CAAC,OAAA,EAAS;AACZ,MAAA,IAAA,CAAK,QAAA,EAAU,CAAC,CAAA;AAChB,MAAA,IAAA,CAAK,WAAA,EAAa,KAAA;AAClB,MAAA,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,QAAA,EAAU,OAAA;AACf,IAAA,IAAA,CAAK,WAAA,EAAa,IAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAA,CAAc,OAAA,EAA8B;AAC1C,IAAA,IAAA,CAAK,QAAA,EAAU,EAAE,GAAG,IAAA,CAAK,OAAA,EAAS,GAAG,QAAQ,CAAA;AAC7C,IAAA,IAAA,CAAK,WAAA,EAAa,IAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,UAAA,CAAA,EAAkC;AAChC,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,CAAA,EAA0B;AACxB,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAA,CAAqB,EAAE,oBAAA,EAAsB,oBAAoB,CAAA,EAA+B;AAC9F,IAAA,GAAA,CAAI,oBAAA,CAAqB,cAAA,CAAe,CAAA,EAAG;AACzC,MAAA,MAAM,cAAA,EAAgB,oBAAA,CAAqB,UAAA,CAAW,CAAA;AACtD,MAAA,mBAAA,CAAoB,UAAA,CAAW,EAAE,GAAG,cAAc,CAAC,CAAA;AAAA,IACrD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,CAAA,EAAyB;AACvB,IAAA,MAAM,MAAA,EAAQ,IAAI,sBAAA,CAAsB,CAAA;AACxC,IAAA,KAAA,CAAM,UAAA,CAAW;AAAA,MACf,GAAG,IAAA,CAAK;AAAA,IACV,CAAC,CAAA;AACD,IAAA,KAAA,CAAM,WAAA,EAAa,IAAA,CAAK,UAAA;AACxB,IAAA,OAAO,KAAA;AAAA,EACT;AACF,UAAA;ADbA;AACA;AEpDO,IAAM,mBAAA,EAAN,MAAM,oBAA8C;AAAA,EACzD,UAAA,CAAW,OAAA,EAAqC;AAAA,EAAC;AAAA,EACjD,aAAA,CAAc,OAAA,EAA8B;AAAA,EAAC;AAAA,EAC7C,UAAA,CAAA,EAAkC;AAChC,IAAA,OAAO,CAAC,CAAA;AAAA,EACV;AAAA,EACA,cAAA,CAAA,EAA0B;AACxB,IAAA,OAAO,KAAA;AAAA,EACT;AAAA,EACA,oBAAA,CAAqB,MAAA,EAAa;AAAA,EAAC;AAAA,EACnC,KAAA,CAAA,EAAyB;AACvB,IAAA,OAAO,IAAI,mBAAA,CAAmB,CAAA;AAAA,EAChC;AACF,CAAA;AFyDA;AACE;AACA;AACF,uGAAC","file":"/home/runner/work/loglayer/loglayer/packages/core/context-manager/dist/index.cjs","sourcesContent":[null,"import type { IContextManager } from \"@loglayer/shared\";\nimport type { OnChildLoggerCreatedParams } from \"@loglayer/shared\";\n\n/**\n * The default context manager used by LogLayer. It is a simple k/v store for context data.\n *\n * @see {@link https://loglayer.dev/context-managers/default.html | Default Context Manager Docs}\n */\nexport class DefaultContextManager implements IContextManager {\n  private context: Record<string, any> = {};\n  private hasContext = false;\n\n  /**\n   * Sets the context data to be included with every log entry. Set to `undefined` to clear the context data.\n   */\n  setContext(context?: Record<string, any>): void {\n    if (!context) {\n      this.context = {};\n      this.hasContext = false;\n      return;\n    }\n\n    this.context = context;\n    this.hasContext = true;\n  }\n\n  /**\n   * Appends context data to the existing context data.\n   */\n  appendContext(context: Record<string, any>) {\n    this.context = { ...this.context, ...context };\n    this.hasContext = true;\n  }\n\n  /**\n   * Returns the context data to be included with every log entry.\n   */\n  getContext(): Record<string, any> {\n    return this.context;\n  }\n\n  /**\n   * Returns true if context data is present.\n   */\n  hasContextData(): boolean {\n    return this.hasContext;\n  }\n\n  /**\n   * Copies the parent context data to the child context data.\n   */\n  onChildLoggerCreated({ parentContextManager, childContextManager }: OnChildLoggerCreatedParams) {\n    if (parentContextManager.hasContextData()) {\n      const parentContext = parentContextManager.getContext();\n      childContextManager.setContext({ ...parentContext });\n    }\n  }\n\n  /**\n   * Creates a new instance of the context manager with the same context data.\n   */\n  clone(): IContextManager {\n    const clone = new DefaultContextManager();\n    clone.setContext({\n      ...this.context,\n    });\n    clone.hasContext = this.hasContext;\n    return clone;\n  }\n}\n","import type { IContextManager } from \"@loglayer/shared\";\n\n/**\n * A mock context manager that does nothing. Useful for use with unit testing.\n */\nexport class MockContextManager implements IContextManager {\n  setContext(context?: Record<string, any>): void {}\n  appendContext(context: Record<string, any>) {}\n  getContext(): Record<string, any> {\n    return {};\n  }\n  hasContextData(): boolean {\n    return false;\n  }\n  onChildLoggerCreated(params: any) {}\n  clone(): IContextManager {\n    return new MockContextManager();\n  }\n}\n"]}