common-types
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -46,2 +46,9 @@ /** | ||
} | ||
export declare type LAMBDA_CALLBACK = (error: any, response: IAWSGatewayResponse) => void; | ||
export interface IAWSGatewayResponse { | ||
statusCode: number; | ||
headers?: IDictionary<string>; | ||
body?: string; | ||
error?: string; | ||
} | ||
/** A decorator signature for a class property */ | ||
@@ -53,3 +60,3 @@ export declare type PropertyDecorator = (target: any, key: string | symbol) => void; | ||
get: () => T; | ||
set: (value: any) => void; | ||
set: (value?: any) => void; | ||
enumerable: boolean; | ||
@@ -56,0 +63,0 @@ configurable: boolean; |
@@ -23,3 +23,2 @@ "use strict"; | ||
})(FirebaseEvent = exports.FirebaseEvent || (exports.FirebaseEvent = {})); | ||
; | ||
class VerboseError extends Error { | ||
@@ -44,25 +43,38 @@ static stackParser(err) { | ||
if (stackFrames) { | ||
this.stackFrames = stackFrames | ||
.filter(frame => (frame.getFileName() || '').indexOf('common-types') === -1); | ||
this.stackFrames = stackFrames.filter(frame => (frame.getFileName() || "").indexOf("common-types") === -1); | ||
this.function = stackFrames[0].getMethodName(); | ||
this.stack = this.message + "\n\n" + this.stackFrames.map(frame => { | ||
const isNative = typeof frame.isNative === 'function' ? frame.isNative() : frame.isNative; | ||
const colorize = (content) => VerboseError.useColor && isNative ? chalk.grey.italic(content) : content; | ||
const className = frame.getTypeName() ? frame.getTypeName() + ' → ' : ''; | ||
const functionName = frame.getMethodName() || frame.getFunctionName() || '<anonymous>'; | ||
const classAndFunction = VerboseError.useColor | ||
? chalk.bold(`${className}${functionName}`) | ||
: `${className}${functionName}`; | ||
const fileName = (frame.getFileName() || '') | ||
.split('/') | ||
.slice(-1 * VerboseError.filePathDepth) | ||
.join('/'); | ||
const details = isNative | ||
? '( native function )' | ||
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${fileName} ]`; | ||
return colorize(`\t at ${classAndFunction} ${details}`); | ||
}).join("\n"); | ||
this.stack = | ||
this.message + | ||
"\n\n" + | ||
this.stackFrames | ||
.map(frame => { | ||
const isNative = typeof frame.isNative === "function" | ||
? frame.isNative() | ||
: frame.isNative; | ||
const colorize = (content) => VerboseError.useColor && isNative | ||
? chalk.grey.italic(content) | ||
: content; | ||
const className = frame.getTypeName() | ||
? frame.getTypeName() + " → " | ||
: ""; | ||
const functionName = frame.getMethodName() || frame.getFunctionName() || "<anonymous>"; | ||
const classAndFunction = VerboseError.useColor | ||
? chalk.bold(`${className}${functionName}`) | ||
: `${className}${functionName}`; | ||
const fileName = (frame.getFileName() || "") | ||
.split("/") | ||
.slice(-1 * VerboseError.filePathDepth) | ||
.join("/"); | ||
const details = isNative | ||
? "( native function )" | ||
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${fileName} ]`; | ||
return colorize(`\t at ${classAndFunction} ${details}`); | ||
}) | ||
.join("\n"); | ||
} | ||
else { | ||
this.stack = this.stack.split("\n").filter(line => line.indexOf('VerboseError') === -1).join("\n"); | ||
this.stack = this.stack | ||
.split("\n") | ||
.filter(line => line.indexOf("VerboseError") === -1) | ||
.join("\n"); | ||
} | ||
@@ -80,3 +92,3 @@ } | ||
message: this.message, | ||
module: this.module, | ||
module: this.module | ||
}; | ||
@@ -83,0 +95,0 @@ } |
{ | ||
"name": "common-types", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Common types not included in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "lib/common-types.js", |
@@ -1,3 +0,3 @@ | ||
import chalk = require('chalk'); | ||
/** | ||
import chalk = require("chalk"); | ||
/** | ||
* A Javascript hash which allows for any set of keys | ||
@@ -36,6 +36,6 @@ */ | ||
export enum STAGE { | ||
prod = 'prod', | ||
stage = 'stage', | ||
test = 'test', | ||
dev = 'dev', | ||
prod = "prod", | ||
stage = "stage", | ||
test = "test", | ||
dev = "dev", | ||
production = prod, | ||
@@ -48,9 +48,21 @@ staging = stage, | ||
export enum FirebaseEvent { | ||
value = 'value', | ||
child_added = 'child_added', | ||
child_moved = 'child_moved', | ||
child_removed = 'child_removed', | ||
child_changed = 'child_changed' | ||
}; | ||
value = "value", | ||
child_added = "child_added", | ||
child_moved = "child_moved", | ||
child_removed = "child_removed", | ||
child_changed = "child_changed" | ||
} | ||
export type LAMBDA_CALLBACK = ( | ||
error: any, | ||
response: IAWSGatewayResponse | ||
) => void; | ||
export interface IAWSGatewayResponse { | ||
statusCode: number; | ||
headers?: IDictionary<string>; | ||
body?: string; | ||
error?: string; | ||
} | ||
// DECORATORS | ||
@@ -61,6 +73,8 @@ | ||
/** A decorator signature for a class */ | ||
export type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void; | ||
export type ClassDecorator = <TFunction extends Function>( | ||
target: TFunction | ||
) => TFunction | void; | ||
export interface ReflectionProperty<T> { | ||
get: () => T; | ||
set: (value: any) => void; | ||
set: (value?: any) => void; | ||
enumerable: boolean; | ||
@@ -70,3 +84,2 @@ configurable: boolean; | ||
// ERRORS | ||
@@ -85,3 +98,3 @@ export interface IVerboseError { | ||
export type LazyString = () => string; | ||
export interface IStackFrame { | ||
export interface IStackFrame { | ||
getTypeName: LazyString; | ||
@@ -102,3 +115,3 @@ getFunctionName: LazyString; | ||
* If you want to use a library like stack-trace(node) or stacktrace-js(client) add in the "get" | ||
* function that they provide | ||
* function that they provide | ||
*/ | ||
@@ -124,26 +137,46 @@ public static setStackParser(fn: (err: IVerboseError) => any) { | ||
const stackFrames = VerboseError.stackParser(this); | ||
if(stackFrames) { | ||
this.stackFrames = stackFrames | ||
.filter(frame => (frame.getFileName() || '').indexOf('common-types') === -1); | ||
if (stackFrames) { | ||
this.stackFrames = stackFrames.filter( | ||
frame => (frame.getFileName() || "").indexOf("common-types") === -1 | ||
); | ||
this.function = stackFrames[0].getMethodName(); | ||
this.stack = this.message + "\n\n" + this.stackFrames.map(frame => { | ||
const isNative = typeof frame.isNative === 'function' ? frame.isNative() : frame.isNative; | ||
const colorize = (content: string) => VerboseError.useColor && isNative ? chalk.grey.italic(content) : content; | ||
const className = frame.getTypeName() ? frame.getTypeName() + ' → ' : ''; | ||
const functionName = frame.getMethodName() || frame.getFunctionName() || '<anonymous>'; | ||
const classAndFunction = VerboseError.useColor | ||
? chalk.bold(`${className}${functionName}`) | ||
: `${className}${functionName}`; | ||
const fileName = (frame.getFileName() || '') | ||
.split('/') | ||
.slice(-1 * VerboseError.filePathDepth) | ||
.join('/'); | ||
const details = isNative | ||
? '( native function )' | ||
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${fileName} ]`; | ||
return colorize(`\t at ${classAndFunction} ${details}`); | ||
}).join("\n"); | ||
this.stack = | ||
this.message + | ||
"\n\n" + | ||
this.stackFrames | ||
.map(frame => { | ||
const isNative = | ||
typeof frame.isNative === "function" | ||
? frame.isNative() | ||
: frame.isNative; | ||
const colorize = (content: string) => | ||
VerboseError.useColor && isNative | ||
? chalk.grey.italic(content) | ||
: content; | ||
const className = frame.getTypeName() | ||
? frame.getTypeName() + " → " | ||
: ""; | ||
const functionName = | ||
frame.getMethodName() || frame.getFunctionName() || "<anonymous>"; | ||
const classAndFunction = VerboseError.useColor | ||
? chalk.bold(`${className}${functionName}`) | ||
: `${className}${functionName}`; | ||
const fileName = (frame.getFileName() || "") | ||
.split("/") | ||
.slice(-1 * VerboseError.filePathDepth) | ||
.join("/"); | ||
const details = isNative | ||
? "( native function )" | ||
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${ | ||
fileName | ||
} ]`; | ||
return colorize(`\t at ${classAndFunction} ${details}`); | ||
}) | ||
.join("\n"); | ||
} else { | ||
this.stack = this.stack.split("\n").filter(line => line.indexOf('VerboseError') === -1).join("\n"); | ||
this.stack = this.stack | ||
.split("\n") | ||
.filter(line => line.indexOf("VerboseError") === -1) | ||
.join("\n"); | ||
} | ||
@@ -164,5 +197,5 @@ } | ||
message: this.message, | ||
module: this.module, | ||
module: this.module | ||
}; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
17665
397
8