traceable.d.ts 1.2 KB

123456789101112131415161718192021222324
  1. import { RunTree } from "../run_trees.js";
  2. import { TraceableFunction } from "./types.js";
  3. interface AsyncLocalStorageInterface {
  4. getStore: () => RunTree | undefined;
  5. run: (context: RunTree | undefined, fn: () => void) => void;
  6. }
  7. declare class AsyncLocalStorageProvider {
  8. getInstance(): AsyncLocalStorageInterface;
  9. initializeGlobalInstance(instance: AsyncLocalStorageInterface): void;
  10. }
  11. export declare const AsyncLocalStorageProviderSingleton: AsyncLocalStorageProvider;
  12. /**
  13. * Return the current run tree from within a traceable-wrapped function.
  14. * Will throw an error if called outside of a traceable function.
  15. *
  16. * @returns The run tree for the given context.
  17. */
  18. export declare function getCurrentRunTree(): RunTree;
  19. export declare function getCurrentRunTree(permitAbsentRunTree: false): RunTree;
  20. export declare function getCurrentRunTree(permitAbsentRunTree: boolean): RunTree | undefined;
  21. export declare function withRunTree<Fn extends (...args: any[]) => any>(runTree: RunTree, fn: Fn): Promise<Awaited<ReturnType<Fn>>>;
  22. export declare const ROOT: unique symbol;
  23. export declare function isTraceableFunction(x: unknown): x is TraceableFunction<any>;
  24. export type { TraceableFunction } from "./types.js";