forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacktrace-js.d.ts
93 lines (81 loc) · 3.1 KB
/
stacktrace-js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Type definitions for stacktrace.js
// Project: https://github.com/stacktracejs/stacktrace.js
// Definitions by: Exceptionless <https://github.com/exceptionless>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace StackTrace {
export interface SourceCache {
[key: string]: string | Promise<string>;
}
/**
* Options for StackTrace
* @param filter Function(StackFrame => Boolean) - Only include stack entries matching for which filter returns true
* @param sourceCache Object (String URL => String Source) - Pre-populate source cache to avoid network requests
* @param offline Boolean (default: false) - Set to true to prevent all network requests
*/
export interface StackTraceOptions {
filter?: (stackFrame: StackFrame) => boolean;
sourceCache?: SourceCache;
offline?: boolean;
}
export interface StackFrame {
constructor(functionName: string, args: any, fileName: string, lineNumber: number, columnNumber: number): StackFrame;
functionName: string;
args: any;
fileName: string;
lineNumber: number;
columnNumber: number;
source: string;
isEval: boolean;
isNative: boolean;
toString(): string;
}
/**
* Get a backtrace from invocation point.
* @param options Options Object
* @return Array[StackFrame]
*/
export function get(options?: StackTraceOptions): Promise<StackFrame[]>;
/**
* Given an error object, parse it.
* @param error Error object
* @param options Object for options
* @return Array[StackFrame]
*/
export function fromError(error: Error, options?: StackTraceOptions): Promise<StackFrame[]>;
/**
* Use StackGenerator to generate a backtrace.
* @param options Object options
* @returns Array[StackFrame]
*/
export function generateArtificially(options?: StackTraceOptions): Promise<StackFrame[]>;
/**
* Given a function, wrap it such that invocations trigger a callback that
* is called with a stack trace.
*
* @param {Function} fn to be instrumented
* @param {Function} callback function to call with a stack trace on invocation
* @param {Function} errback optional function to call with error if unable to get stack trace.
* @param {Object} thisArg optional context object (e.g. window)
* @return {Function} instrumented function
*/
export function instrument<TFunc extends Function>(fn: TFunc, callback: (stackFrames: StackFrame[]) => void, errback?: (error: Error) => void, thisArg?: any): TFunc;
/**
* Given a function that has been instrumented,
* revert the function to it's original (non-instrumented) state.
*
* @param fn {Function}
* @return {Function} original function
*/
export function deinstrument<TFunc extends Function>(fn: TFunc): TFunc;
/**
* Given an Array of StackFrames, serialize and POST to given URL.
*
* @param stackframes - Array[StackFrame]
* @param url - URL as String
* @return Promise<string>
*/
export function report(stackframes: StackFrame[], url: string): Promise<string>;
}
declare module "stacktrace-js" {
export = StackTrace;
}