result-tsk
Advanced tools
Comparing version 2.1.8 to 2.1.9
@@ -120,3 +120,3 @@ # Changelog | ||
## [2.1.7] — 2024-06-07 | ||
## [2.1.7] — 2024-07-06 | ||
@@ -127,3 +127,3 @@ ### Update | ||
## [2.1.8] — 2024-06-07 | ||
## [2.1.8] — 2024-07-06 | ||
@@ -133,1 +133,7 @@ ### Update | ||
- keeping value content in Result<T>. | ||
## [2.1.9] — 2024-07-30 | ||
### Update | ||
- Improvement result execution |
@@ -0,4 +1,4 @@ | ||
import { ResultExecutionPromise } from "../Types"; | ||
import { Metadata } from "../Result.interface"; | ||
import { IResult } from "./Result.interface"; | ||
import { ResultExecution } from "../Types"; | ||
import { ResultDto } from "../ResultDto"; | ||
@@ -23,3 +23,3 @@ export declare class Result<T> implements IResult<T> { | ||
setData(data: string | T, statusCode: number | string, message?: string): IResult<T>; | ||
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult<T> & { | ||
execute<RO>(promise: ResultExecutionPromise<RO>): Promise<IResult<T> & { | ||
value: RO; | ||
@@ -26,0 +26,0 @@ }>; |
@@ -83,7 +83,14 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const execution = yield promise; | ||
if (execution.error) { | ||
this.setError(execution.error, execution.statusCode); | ||
} | ||
const value = execution.value; | ||
const value = yield promise.then((execution) => { | ||
if (execution.error) { | ||
this.setError(execution.error, execution.statusCode); | ||
} | ||
return execution.value; | ||
}).catch((error) => { | ||
console.error(`Error on result execute ${new Date().toISOString()}: ${JSON.stringify({ message: error.message, stack: error.stack })}`); | ||
const errorMessage = (error === null || error === void 0 ? void 0 : error.statusCode) ? `${error.message}` : `Unexpected application error on execute: ${error.message}`; | ||
const statusCode = (error === null || error === void 0 ? void 0 : error.statusCode) || 500; | ||
this.setError(errorMessage, statusCode); | ||
return null; | ||
}); | ||
return Object.assign(Object.assign({}, this), { value }); | ||
@@ -90,0 +97,0 @@ }); |
@@ -1,3 +0,3 @@ | ||
import { ResultExecution } from "./Types"; | ||
import { Metadata, IResult } from "./Result.interface"; | ||
import { ResultExecutionPromise } from "./Types"; | ||
import { ResultDto } from "./ResultDto"; | ||
@@ -19,3 +19,3 @@ export declare class Result implements IResult { | ||
hasMessage(): boolean; | ||
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult & { | ||
execute<RO>(promise: ResultExecutionPromise<RO>): Promise<IResult & { | ||
value: RO; | ||
@@ -22,0 +22,0 @@ }>; |
@@ -42,3 +42,2 @@ "use strict"; | ||
return __classPrivateFieldGet(this, _Result_metadata, "f"); | ||
return this; | ||
} | ||
@@ -73,7 +72,14 @@ hasMetadata() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const execution = yield promise; | ||
if (execution.error) { | ||
this.setError(execution.error, execution.statusCode); | ||
} | ||
const value = execution.value; | ||
const value = yield promise.then((execution) => { | ||
if (execution.error) { | ||
this.setError(execution.error, execution.statusCode); | ||
} | ||
return execution.value; | ||
}).catch((error) => { | ||
console.error(`Error on result execute ${new Date().toISOString()}: ${JSON.stringify({ message: error.message, stack: error.stack })}`); | ||
const errorMessage = (error === null || error === void 0 ? void 0 : error.statusCode) ? `${error.message}` : `Unexpected application error on execute: ${error.message}`; | ||
const statusCode = (error === null || error === void 0 ? void 0 : error.statusCode) || 500; | ||
this.setError(errorMessage, statusCode); | ||
return null; | ||
}); | ||
return Object.assign(Object.assign({}, this), { value }); | ||
@@ -80,0 +86,0 @@ }); |
{ | ||
"name": "result-tsk", | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"description": "result tool to use with or without NodeTskeleton template project", | ||
@@ -34,6 +34,6 @@ "repository": { | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"typescript": "^5.5.2" | ||
"@types/node": "^20.14.13", | ||
"typescript": "^5.5.4" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -34,3 +34,3 @@ # Result tool 🧰 | ||
result.setError( | ||
this.resources.get(this.resourceKeys.PRODUCT_DOES_NOT_EXIST), | ||
this.resources.get(this.resources.keys.PRODUCT_DOES_NOT_EXIST), | ||
this.resultCodes.NOT_FOUND, | ||
@@ -60,3 +60,3 @@ ); | ||
return { | ||
error: this.resources.get(this.resourceKeys.PRODUCT_DOES_NOT_EXIST), | ||
error: this.resources.get(this.resources.keys.PRODUCT_DOES_NOT_EXIST), | ||
statusCode: this.resultCodes.NOT_FOUND, | ||
@@ -88,3 +88,3 @@ value: null, | ||
expect(result.error).toBe( | ||
resources.getWithParams(resourceKeys.SOME_PARAMETERS_ARE_MISSING, { | ||
resources.getWithParams(resources.keys.SOME_PARAMETERS_ARE_MISSING, { | ||
missingParams: "quantity", | ||
@@ -91,0 +91,0 @@ }), |
25117
355