Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

result-tsk

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

result-tsk - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

lib/Types.d.ts

7

CHANGELOG.md

@@ -106,1 +106,8 @@ # Changelog

- Packages was updated and some methods was added
## [2.1.4] — 2023-12-09
### Update
- Packages was updated
- Feature to execute promise and control the error was added to able the perform to use of pure functions

4

lib/generic/Result.d.ts
import { Metadata } from "../Result.interface";
import { IResult } from "./Result.interface";
import { ResultDto } from "../ResultDto";
import { ResultExecution } from "../Types";
export declare class Result<T> implements IResult<T> {

@@ -22,3 +23,6 @@ #private;

setData(data: string | T, statusCode: number | string, message?: string): void;
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult<T> & {
value: RO;
}>;
toResultDto(): ResultDto;
}
import { IBaseResult } from "../Result.interface";
import { ResultExecution } from "../Types";
import { ResultDto } from "../ResultDto";

@@ -9,2 +10,5 @@ export interface IResult<T> extends IBaseResult {

toResultDto(): ResultDto;
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult<T> & {
value: RO;
}>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

@@ -66,2 +75,15 @@ if (kind === "m") throw new TypeError("Private method is not writable");

}
execute(promise) {
return __awaiter(this, void 0, void 0, function* () {
let value = undefined;
const execution = yield promise;
if (execution.error) {
this.setError(execution.error, execution.statusCode);
}
else {
value = execution.value;
}
return Object.assign(Object.assign({}, this), { value });
});
}
toResultDto() {

@@ -68,0 +90,0 @@ const result = new ResultDto_1.ResultDto();

@@ -5,1 +5,2 @@ export { IResult } from "./Result.interface";

export { Result as ResultT } from "./generic/Result";
export { ResultExecution, ResultExecutionPromise } from "./Types";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,1 +1,2 @@

import { ResultExecution } from "./Types";
import { Metadata, IResult } from "./Result.interface";

@@ -18,3 +19,6 @@ import { ResultDto } from "./ResultDto";

hasMessage(): boolean;
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult & {
value: RO;
}>;
toResultDto(): ResultDto;
}

8

lib/Result.interface.d.ts

@@ -0,3 +1,4 @@

import { ResultExecution } from "./Types";
import { ResultDto } from "./ResultDto";
declare type Metadata = Record<string, any>;
type Metadata = Record<string, any>;
export interface IResult {

@@ -18,4 +19,7 @@ statusCode: number | string;

hasMetadata(): boolean;
execute<RO>(promise: Promise<ResultExecution<RO>>): Promise<IResult & {
value: RO;
}>;
}
export declare type IBaseResult = Omit<IResult, "toResultDto">;
export type IBaseResult = Omit<IResult, "toResultDto">;
export { Metadata };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

@@ -55,2 +64,15 @@ if (kind === "m") throw new TypeError("Private method is not writable");

}
execute(promise) {
return __awaiter(this, void 0, void 0, function* () {
let value = undefined;
const execution = yield promise;
if (execution.error) {
this.setError(execution.error, execution.statusCode);
}
else {
value = execution.value;
}
return Object.assign(Object.assign({}, this), { value });
});
}
toResultDto() {

@@ -57,0 +79,0 @@ const result = new ResultDto_1.ResultDto();

@@ -0,0 +0,0 @@ export declare class ResultDto {

@@ -0,0 +0,0 @@ "use strict";

{
"name": "result-tsk",
"version": "2.1.3",
"version": "2.1.4",
"description": "result tool to use with or without NodeTskeleton template project",

@@ -34,6 +34,6 @@ "repository": {

"devDependencies": {
"@types/node": "^18.0.6",
"typescript": "^4.7.4"
"@types/node": "^18.19.3",
"typescript": "^5.3.3"
},
"dependencies": {}
}

@@ -14,3 +14,3 @@ # Result tool 🧰

```ts
import { IResultT, ResultT } from "result-tsk";
import { IResultT, ResultT, } from "result-tsk";

@@ -25,2 +25,3 @@ export class UseCaseProductGet extends BaseUseCase {

const result = new ResultT<ProductDto>();
// With the resulting object we can control validations within other functions.

@@ -30,2 +31,3 @@ if (!this.validator.isValidEntry(result, { productMaskId: idMask })) {

}
const product: Product = await this.productQueryService.getByMaskId(idMask);

@@ -40,5 +42,11 @@ if (!product) {

}
// Or
if (result.hasError()) return result;
// Or
// The result object helps us with manage the executing flow.
const { value: product } = await result.execute(this.getProduct());
if (result.hasError()) return result;
const productDto = this.mapper.mapObject<Product, ProductDto>(product, new ProductDto());

@@ -50,2 +58,15 @@ // The result object also helps you with the response data.

}
private async getProduct(): ResultExecutionPromise<Product> {
const product: Product = await this.productQueryService.getByMaskId(idMask);
if (!product) {
return {
error: this.resources.get(this.resourceKeys.PRODUCT_DOES_NOT_EXIST),
statusCode: this.resultCodes.NOT_FOUND,
value: null,
}
}
return { value: product };
}
}

@@ -52,0 +73,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc