1 | // Type definitions for stacktrace.js v2.0.0
|
---|
2 | // Project: https://github.com/stacktracejs/stacktrace.js
|
---|
3 | // Definitions by: Eric Wendelin <https://github.com/exceptionless>
|
---|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
---|
5 |
|
---|
6 | declare namespace StackTrace {
|
---|
7 |
|
---|
8 | export interface SourceCache {
|
---|
9 | [key: string]: string | Promise<string>;
|
---|
10 | }
|
---|
11 |
|
---|
12 | export interface StackTraceOptions {
|
---|
13 | filter?: (stackFrame: StackFrame) => boolean;
|
---|
14 | sourceCache?: SourceCache;
|
---|
15 | offline?: boolean;
|
---|
16 | }
|
---|
17 |
|
---|
18 | export interface StackFrame {
|
---|
19 | constructor(object: StackFrame): StackFrame;
|
---|
20 |
|
---|
21 | isConstructor?: boolean;
|
---|
22 | getIsConstructor(): boolean;
|
---|
23 | setIsConstructor(): void;
|
---|
24 |
|
---|
25 | isEval?: boolean;
|
---|
26 | getIsEval(): boolean;
|
---|
27 | setIsEval(): void;
|
---|
28 |
|
---|
29 | isNative?: boolean;
|
---|
30 | getIsNative(): boolean;
|
---|
31 | setIsNative(): void;
|
---|
32 |
|
---|
33 | isTopLevel?: boolean;
|
---|
34 | getIsTopLevel(): boolean;
|
---|
35 | setIsTopLevel(): void;
|
---|
36 |
|
---|
37 | columnNumber?: number;
|
---|
38 | getColumnNumber(): number;
|
---|
39 | setColumnNumber(): void;
|
---|
40 |
|
---|
41 | lineNumber?: number;
|
---|
42 | getLineNumber(): number;
|
---|
43 | setLineNumber(): void;
|
---|
44 |
|
---|
45 | fileName?: string;
|
---|
46 | getFileName(): string;
|
---|
47 | setFileName(): void;
|
---|
48 |
|
---|
49 | functionName?: string;
|
---|
50 | getFunctionName(): string;
|
---|
51 | setFunctionName(): void;
|
---|
52 |
|
---|
53 | source?: string;
|
---|
54 | getSource(): string;
|
---|
55 | setSource(): void;
|
---|
56 |
|
---|
57 | args?: any[];
|
---|
58 | getArgs(): any[];
|
---|
59 | setArgs(): void;
|
---|
60 |
|
---|
61 | evalOrigin?: StackFrame;
|
---|
62 | getEvalOrigin(): StackFrame;
|
---|
63 | setEvalOrigin(): void;
|
---|
64 |
|
---|
65 | toString(): string;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Get a backtrace from invocation point.
|
---|
70 | *
|
---|
71 | * @param options Options Object
|
---|
72 | * @return Array[StackFrame]
|
---|
73 | */
|
---|
74 | export function get(options?: StackTraceOptions): Promise<StackFrame[]>;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Get a backtrace from invocation point, synchronously. Does not
|
---|
78 | * attempt to map sources.
|
---|
79 | *
|
---|
80 | * @param options Options Object
|
---|
81 | * @return Array[StackFrame]
|
---|
82 | */
|
---|
83 | export function getSync(options?: StackTraceOptions): StackFrame[];
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Given an error object, parse it.
|
---|
87 | *
|
---|
88 | * @param error Error object
|
---|
89 | * @param options Object for options
|
---|
90 | * @return Array[StackFrame]
|
---|
91 | */
|
---|
92 | export function fromError(error: Error, options?: StackTraceOptions): Promise<StackFrame[]>;
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Use StackGenerator to generate a backtrace.
|
---|
96 | * @param options Object options
|
---|
97 | * @returns Array[StackFrame]
|
---|
98 | */
|
---|
99 | export function generateArtificially(options?: StackTraceOptions): Promise<StackFrame[]>;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Given a function, wrap it such that invocations trigger a callback that
|
---|
103 | * is called with a stack trace.
|
---|
104 | *
|
---|
105 | * @param {Function} fn to be instrumented
|
---|
106 | * @param {Function} callback function to call with a stack trace on invocation
|
---|
107 | * @param {Function} errback optional function to call with error if unable to get stack trace.
|
---|
108 | * @param {Object} thisArg optional context object (e.g. window)
|
---|
109 | */
|
---|
110 | export function instrument<TFunc extends Function>(fn: TFunc, callback: (stackFrames: StackFrame[]) => void, errback?: (error: Error) => void, thisArg?: any): TFunc;
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Given a function that has been instrumented,
|
---|
114 | * revert the function to it's original (non-instrumented) state.
|
---|
115 | *
|
---|
116 | * @param fn {Function}
|
---|
117 | */
|
---|
118 | export function deinstrument<TFunc extends Function>(fn: TFunc): TFunc;
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Given an Array of StackFrames, serialize and POST to given URL.
|
---|
122 | *
|
---|
123 | * @param stackframes - Array[StackFrame]
|
---|
124 | * @param url - URL as String
|
---|
125 | * @param errorMsg - Error message as String
|
---|
126 | * @param requestOptions - Object with headers information
|
---|
127 | * @return Promise<any>
|
---|
128 | */
|
---|
129 | export function report(stackframes: StackFrame[], url: string, errorMsg?: string, requestOptions?: object): Promise<any>;
|
---|
130 | }
|
---|
131 |
|
---|
132 | declare module "stacktrace-js" {
|
---|
133 | export = StackTrace;
|
---|
134 | }
|
---|