diff --git a/package.json b/package.json index 0ad3de1..4406206 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,12 @@ "url": "https://github.com/stacktracejs/stacktrace-gps/issues" }, "main": "./stacktrace-gps.js", + "types": "./stacktrace-gps.d.ts", "files": [ "LICENSE", "README.md", "stacktrace-gps.js", + "stacktrace-gps.d.ts", "dist/", "node_modules/source-map/" ], diff --git a/stacktrace-gps.d.ts b/stacktrace-gps.d.ts new file mode 100644 index 0000000..1535200 --- /dev/null +++ b/stacktrace-gps.d.ts @@ -0,0 +1,62 @@ +import { SourceMapConsumer } from "source-map"; +import StackFrame = require("stackframe"); + +declare namespace StackTraceGPS { + /** + * Options for the StackTraceGPS constructor + */ + interface Options { + /** Pre-populate source cache to avoid network requests */ + sourceCache?: { [url: string]: string | Promise }; + + /** Pre-populate SourceMapConsumer cache to avoid network requests */ + sourceMapConsumerCache?: { [sourceMappingUrl: string]: SourceMapConsumer }; + + /** True to prevent network requests (best effort without sources or source maps) */ + offline?: boolean; + + /** Function to be used for making X-Domain requests */ + ajax?(url: string): Promise; + + /** Function to convert base64-encoded strings to their original representation */ + atob?(base64: string): string; + } +} + +declare class StackTraceGPS { + /** + * @param opts - StackTraceGPS.Options object + */ + constructor(opts?: StackTraceGPS.Options); + + /** + * Given a StackFrame, enhance function name and use source maps for + * a better StackFrame. + * + * @param stackframe - StackFrame object + * @returns Promise that resolves with with source-mapped StackFrame + */ + pinpoint(stackframe: StackFrame): Promise; + + /** + * Given a StackFrame, guess function name from location + * information. + * + * @param stackframe - StackFrame object + * @returns Promise that resolves with enhanced StackFrame + */ + findFunctionName(stackframe: StackFrame): Promise; + + /** + * Given a StackFrame, seek source-mapped location and return new + * enhanced StackFrame. + * + * @param stackframe - StackFrame object + * @returns Promise that resolves with enhanced StackFrame + */ + getMappedLocation(stackframe: StackFrame): Promise; +} + +export = StackTraceGPS; + +export as namespace StackTraceGPS; // global for non-module UMD users