@litert/core
Advanced tools
Comparing version
# Changes Logs | ||
## v0.4.0 | ||
- Now the **origin** only stand for the data carried by Exception. | ||
- Added the property **trace** for Exception to get the trace. | ||
- New method **is** helps determine if an error object is of LiteRT's exception. | ||
- Added asynchronous utility function **sleep**. | ||
## v0.3.3 | ||
@@ -4,0 +11,0 @@ |
@@ -9,3 +9,17 @@ /** | ||
protected _origin: any; | ||
protected _trace: string[]; | ||
/** | ||
* The data needs to be carried by exception. | ||
*/ | ||
readonly origin: any; | ||
/** | ||
* The trace of Exception. | ||
* | ||
* This is an array contains the calling stacks from the new operation of | ||
* an exception. | ||
*/ | ||
readonly trace: string[]; | ||
/** | ||
* The type of the exception. | ||
*/ | ||
readonly type: string; | ||
@@ -25,4 +39,8 @@ /** | ||
* @param message The description about this exception. | ||
* @param origin The data needs to be carried by exception. | ||
*/ | ||
constructor(error: number, message: string, origin?: any); | ||
/** | ||
* @override | ||
*/ | ||
toString(): string; | ||
@@ -33,2 +51,9 @@ /** | ||
toJSON(): string; | ||
/** | ||
* THe method helps determine if an error object is of LiteRT's exception. | ||
* | ||
* @param e The error object to be check. | ||
* @param type The type of exception to be ensured. | ||
*/ | ||
static is(e: any, type?: string): e is Exception; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -14,3 +14,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -23,5 +23,20 @@ */ | ||
class Exception { | ||
/** | ||
* The data needs to be carried by exception. | ||
*/ | ||
get origin() { | ||
return this._origin; | ||
} | ||
/** | ||
* The trace of Exception. | ||
* | ||
* This is an array contains the calling stacks from the new operation of | ||
* an exception. | ||
*/ | ||
get trace() { | ||
return this._trace; | ||
} | ||
/** | ||
* The type of the exception. | ||
*/ | ||
get type() { | ||
@@ -47,2 +62,3 @@ return this._type; | ||
* @param message The description about this exception. | ||
* @param origin The data needs to be carried by exception. | ||
*/ | ||
@@ -52,4 +68,11 @@ constructor(error, message, origin) { | ||
this._message = message; | ||
this._origin = origin || new Error("TRACE"); | ||
this._origin = origin; | ||
this._trace = new Error().stack.split(/\s+at\s+/).slice(2); | ||
/** | ||
* this._type should be defined in the sub classes. | ||
*/ | ||
} | ||
/** | ||
* @override | ||
*/ | ||
toString() { | ||
@@ -66,7 +89,17 @@ return `Error(${this._type} ${this._errno}): ${this.message}`; | ||
"message": this._message, | ||
"origin": this._origin | ||
"origin": this._origin, | ||
"trace": this._trace | ||
}); | ||
} | ||
/** | ||
* THe method helps determine if an error object is of LiteRT's exception. | ||
* | ||
* @param e The error object to be check. | ||
* @param type The type of exception to be ensured. | ||
*/ | ||
static is(e, type) { | ||
return e instanceof Exception && (type === void 0 || type === e.type); | ||
} | ||
} | ||
exports.Exception = Exception; | ||
//# sourceMappingURL=class.Exception.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -14,3 +14,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -17,0 +17,0 @@ */ |
@@ -11,1 +11,3 @@ /** | ||
export * from "./class.RawPromise"; | ||
import * as Async from "./utilities.async"; | ||
export { Async }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -14,3 +14,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -24,2 +24,4 @@ */ | ||
__export(require("./class.RawPromise")); | ||
const Async = require("./utilities.async"); | ||
exports.Async = Async; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@litert/core", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "The core of LiteRT.", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "npm install && npm run clean && npm run lint && npm run build-only", | ||
"clean": "rm -rf ./dist/", | ||
"build-only": "tsc -p .", | ||
"prepare": "npm run build-only", | ||
"lint": "tslint --project tslint.json ./sources/*.ts ./sources/**/*.ts" | ||
"prepare": "npm run rebuild", | ||
"build": "tsc -p .", | ||
"rebuild": "npm run clean && npm run lint && npm run build", | ||
"test": "echo See directory sources/samples", | ||
"clean": "rm -rf index.* server samples", | ||
"lint": "tslint -p . -c tslint.json" | ||
}, | ||
@@ -26,3 +27,3 @@ "repository": { | ||
], | ||
"author": "Angus.Fenying <i.am.x.fenying@gmail.com>", | ||
"author": "Angus.Fenying <fenying@litert.org> (https://fenying.net)", | ||
"license": "Apache-2.0", | ||
@@ -29,0 +30,0 @@ "typings": "dist/index.d.ts", |
@@ -5,3 +5,3 @@ /* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -13,3 +13,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -31,2 +31,7 @@ */ | ||
protected _trace: string[]; | ||
/** | ||
* The data needs to be carried by exception. | ||
*/ | ||
public get origin(): any { | ||
@@ -37,2 +42,16 @@ | ||
/** | ||
* The trace of Exception. | ||
* | ||
* This is an array contains the calling stacks from the new operation of | ||
* an exception. | ||
*/ | ||
public get trace(): string[] { | ||
return this._trace; | ||
} | ||
/** | ||
* The type of the exception. | ||
*/ | ||
public get type(): string { | ||
@@ -64,2 +83,3 @@ | ||
* @param message The description about this exception. | ||
* @param origin The data needs to be carried by exception. | ||
*/ | ||
@@ -70,5 +90,13 @@ public constructor(error: number, message: string, origin?: any) { | ||
this._message = message; | ||
this._origin = origin || new Error("TRACE"); | ||
this._origin = origin; | ||
this._trace = (new Error().stack as string).split(/\s+at\s+/).slice(2); | ||
/** | ||
* this._type should be defined in the sub classes. | ||
*/ | ||
} | ||
/** | ||
* @override | ||
*/ | ||
public toString(): string { | ||
@@ -88,5 +116,17 @@ | ||
"message": this._message, | ||
"origin": this._origin | ||
"origin": this._origin, | ||
"trace": this._trace | ||
}); | ||
} | ||
/** | ||
* THe method helps determine if an error object is of LiteRT's exception. | ||
* | ||
* @param e The error object to be check. | ||
* @param type The type of exception to be ensured. | ||
*/ | ||
public static is(e: any, type?: string): e is Exception { | ||
return e instanceof Exception && (type === void 0 || type === e.type); | ||
} | ||
} |
@@ -5,3 +5,3 @@ /* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -13,3 +13,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -16,0 +16,0 @@ */ |
@@ -5,3 +5,3 @@ /* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2007-2017 Fenying Studio | | ||
| Copyright (c) 2018 Fenying Studio | | ||
+----------------------------------------------------------------------+ | ||
@@ -13,3 +13,3 @@ | This source file is subject to version 2.0 of the Apache license, | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Angus Fenying <i.am.x.fenying@gmail.com> | | ||
| Authors: Angus Fenying <fenying@litert.org> | | ||
+----------------------------------------------------------------------+ | ||
@@ -35,1 +35,5 @@ */ | ||
export * from "./class.RawPromise"; | ||
import * as Async from "./utilities.async"; | ||
export { Async }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
33262
25.65%20
25%498
48.66%