stacktrace-js: Provides its own types (#39547)

This commit is contained in:
Alexander T
2019-10-29 08:00:26 -07:00
committed by Jesse Trinity
parent 1ac4aa639d
commit 6d2d7a3db0
5 changed files with 6 additions and 248 deletions
+6
View File
@@ -3876,6 +3876,12 @@
"sourceRepoURL": "https://servicestack.net/",
"asOfVersion": "0.1.5"
},
{
"libraryName": "stacktrace-js",
"typingsPackageName": "stacktrace-js",
"sourceRepoURL": "https://github.com/stacktracejs/stacktrace.js",
"asOfVersion": "2.0.1"
},
{
"libraryName": "stellar-sdk",
"typingsPackageName": "stellar-sdk",
-107
View File
@@ -1,107 +0,0 @@
// Type definitions for stacktrace.js
// Project: https://github.com/stacktracejs/stacktrace.js
// Definitions by: Exceptionless <https://github.com/exceptionless>
// Chun-Yan Ho <https://github.com/pilagod>
// 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 class StackFrame {
constructor(functionName: string, args: any, fileName: string, lineNumber: number, columnNumber: number);
functionName: string;
args: any;
fileName: string;
lineNumber: number;
columnNumber: number;
source: string;
isEval: boolean;
isNative: boolean;
toString(): string;
}
export interface RequestOptions {
headers: { [id: string]: string };
}
/**
* Get a backtrace from invocation point.
* @param options Options Object
* @return Array[StackFrame]
*/
export function get(options?: StackTraceOptions): Promise<StackFrame[]>;
/**
* Get a backtrace from invocation point synchronously.
* @param options Options Object
* @return Array[StackFrame]
*/
export function getSync(options?: StackTraceOptions): 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 {Array} stackframes - Previously wrapped Function
* @param {string} url - URL to POST stack JSON to
* @param {string} message - Optional Error message
* @param {Object} requestOptions - Request Headers {headers: {key: "value"}}
* @return {Promise<string>} - Promise is resolved with response text from POST request.
*/
export function report(stackframes: StackFrame[], url: string, message?: string, requestOptions?: RequestOptions): Promise<string>;
}
declare module "stacktrace-js" {
export = StackTrace;
}
@@ -1,37 +0,0 @@
function interestingFn(): string {
return 'https://github.com/exceptionless/Exceptionless';
}
const callback = (stackframes: StackTrace.StackFrame[]) => {
const stringifiedStack = stackframes.map((sf: StackTrace.StackFrame): string => {
console.log(sf.functionName);
console.log(sf.args);
console.log(sf.fileName);
console.log(sf.lineNumber);
console.log(sf.columnNumber);
console.log(sf.source);
console.log(sf.isEval);
console.log(sf.isNative);
return sf.toString();
}).join('\n');
console.log(stringifiedStack);
};
const errorCallback = (err: Error) => console.log(err.message);
const logger = (stackframes: StackTrace.StackFrame[]) => console.log(stackframes);
const options: StackTrace.StackTraceOptions = {
filter: (stackframe: StackTrace.StackFrame) => true,
sourceCache: {},
offline: false
};
const error = new Error('BOOM!');
StackTrace.get(options).then(logger);
logger(StackTrace.getSync(options))
StackTrace.fromError(error, options).then(logger);
StackTrace.generateArtificially(options).then(logger);
const instrumented: () => string = StackTrace.instrument(interestingFn, callback, errorCallback);
const original: () => string = StackTrace.deinstrument(interestingFn);
-24
View File
@@ -1,24 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"stacktrace-js-tests.ts"
]
}
-80
View File
@@ -1,80 +0,0 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"npm-naming": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}