UNPKG

@clipboard-health/execution-context

Version:

A lightweight Node.js utility for managing execution contexts and metadata aggregation using AsyncLocalStorage.

28 lines (27 loc) 1.45 kB
import "../types/global"; import type { ExecutionContext } from "../types/types"; export declare function getExecutionContext(): ExecutionContext | undefined; export declare function runWithExecutionContext<T = void>(context: ExecutionContext, callback: () => Promise<T>): Promise<T>; /** * This function is simply a convenience to initialize an empty context object * @param source - The class/service that initializes the context */ export declare function newExecutionContext(source: string): ExecutionContext; /** * A utility function that will add metadata to the current context * @param metadata - the metadata (key-value pair), to be added to the context */ export declare function addMetadataToLocalContext(metadata: Record<string, unknown>): void; /** * A utility function that will add metadata to the list under current context's key * @param key - the list's key (string) in the context * @param metadata - the metadata (key-value pair), to be added to the context */ export declare function addToMetadataList(key: string, metadata: Record<string, unknown>): void; /** * A utility function that will add metadata to the record under current context's key, * supporting nested records. * @param key - the record's key (string) in the context * @param metadata - the metadata (key-value pair), to be added to the context */ export declare function addToMetadataRecord(key: string, metadata: Record<string, unknown>): void;