node-result
Advanced tools
Comparing version 12.1.0 to 13.0.0
@@ -1,5 +0,5 @@ | ||
export declare type TResult<DataType, ErrorType> = ResultOK<DataType> | ResultFAIL<ErrorType>; | ||
export declare type TResultAsync<DataType, ErrorType> = Promise<TResult<DataType, ErrorType>>; | ||
export declare type TErrorProcessing<DataType, ErrorType> = (error: ErrorType) => DataType; | ||
export declare type TErrorProcessingAsync<DataType, ErrorType> = (error: ErrorType) => Promise<DataType>; | ||
export type TResult<DataType, ErrorType> = Ok<DataType> | Err<ErrorType>; | ||
export type TResultAsync<DataType, ErrorType> = Promise<TResult<DataType, ErrorType>>; | ||
export type TErrorProcessing<DataType, ErrorType> = (error: ErrorType) => DataType; | ||
export type TErrorProcessingAsync<DataType, ErrorType> = (error: ErrorType) => Promise<DataType>; | ||
export declare class Result<DataType, ErrorType> { | ||
@@ -10,3 +10,3 @@ protected readonly data: DataType; | ||
} | ||
export declare class ResultOK<DataType> extends Result<DataType, undefined> { | ||
export declare class Ok<DataType> extends Result<DataType, null> { | ||
constructor(data: DataType); | ||
@@ -16,7 +16,7 @@ unwrap(): DataType; | ||
isOk(): boolean; | ||
isFail(): boolean; | ||
isErr(): boolean; | ||
onError(func: TErrorProcessing<DataType, never>): DataType; | ||
onErrorAsync(func: TErrorProcessingAsync<DataType, never>): Promise<DataType>; | ||
} | ||
export declare class ResultFAIL<ErrorType> extends Result<undefined, ErrorType> { | ||
export declare class Err<ErrorType> extends Result<null, ErrorType> { | ||
constructor(error: ErrorType); | ||
@@ -26,9 +26,9 @@ unwrap(): never; | ||
isOk(): boolean; | ||
isFail(): boolean; | ||
isErr(): boolean; | ||
onError<DataType>(func: TErrorProcessing<never, ErrorType>): DataType; | ||
onErrorAsync<DataType>(func: TErrorProcessingAsync<never, ErrorType>): Promise<DataType>; | ||
} | ||
export declare function ok<DataType>(data: DataType): ResultOK<DataType>; | ||
export declare function fail<ErrorType>(error: ErrorType): ResultFAIL<ErrorType>; | ||
export declare function tryCatch<TargetType, DataType, ErrorType>(target: TargetType, property: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => DataType | ResultFAIL<ErrorType>>): TypedPropertyDescriptor<(...args: any[]) => DataType | ResultFAIL<ErrorType>>; | ||
export declare function tryCatchAsync<TargetType, DataType, ErrorType>(target: TargetType, property: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<DataType | ResultFAIL<ErrorType>>>): TypedPropertyDescriptor<(...args: any[]) => Promise<DataType | ResultFAIL<ErrorType>>>; | ||
export declare function ok<DataType>(data: DataType): Ok<DataType>; | ||
export declare function err<ErrorType>(error: ErrorType): Err<ErrorType>; | ||
export declare function tryCatch<TargetType, DataType, ErrorType>(target: TargetType, property: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => DataType | Err<ErrorType>>): TypedPropertyDescriptor<(...args: any[]) => DataType | Err<ErrorType>>; | ||
export declare function tryCatchAsync<TargetType, DataType, ErrorType>(target: TargetType, property: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<DataType | Err<ErrorType>>>): TypedPropertyDescriptor<(...args: any[]) => Promise<DataType | Err<ErrorType>>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tryCatchAsync = exports.tryCatch = exports.fail = exports.ok = exports.ResultFAIL = exports.ResultOK = exports.Result = void 0; | ||
exports.tryCatchAsync = exports.tryCatch = exports.err = exports.ok = exports.Err = exports.Ok = exports.Result = void 0; | ||
class Result { | ||
@@ -11,5 +11,5 @@ constructor(data, error) { | ||
exports.Result = Result; | ||
class ResultOK extends Result { | ||
class Ok extends Result { | ||
constructor(data) { | ||
super(data, undefined); | ||
super(data, null); | ||
} | ||
@@ -25,3 +25,3 @@ unwrap() { | ||
} | ||
isFail() { | ||
isErr() { | ||
return false; | ||
@@ -38,6 +38,6 @@ } | ||
} | ||
exports.ResultOK = ResultOK; | ||
class ResultFAIL extends Result { | ||
exports.Ok = Ok; | ||
class Err extends Result { | ||
constructor(error) { | ||
super(undefined, error); | ||
super(null, error); | ||
} | ||
@@ -53,3 +53,3 @@ unwrap() { | ||
} | ||
isFail() { | ||
isErr() { | ||
return true; | ||
@@ -64,11 +64,11 @@ } | ||
} | ||
exports.ResultFAIL = ResultFAIL; | ||
exports.Err = Err; | ||
function ok(data) { | ||
return new ResultOK(data); | ||
return new Ok(data); | ||
} | ||
exports.ok = ok; | ||
function fail(error) { | ||
return new ResultFAIL(error); | ||
function err(error) { | ||
return new Err(error); | ||
} | ||
exports.fail = fail; | ||
exports.err = err; | ||
function tryCatch(target, property, descriptor) { | ||
@@ -80,10 +80,10 @@ const self = descriptor.value; | ||
if (self instanceof Function) { | ||
return self.call(this, ...args); | ||
return self.apply(this, args); | ||
} | ||
else { | ||
return fail(new TypeError('Descriptor value is not a function.')); | ||
return err(new TypeError('Descriptor value is not a function.')); | ||
} | ||
} | ||
catch (error) { | ||
return fail(error); | ||
return err(error); | ||
} | ||
@@ -100,10 +100,10 @@ }; | ||
if (self instanceof Function) { | ||
return self.call(this, ...args); | ||
return self.apply(this, args); | ||
} | ||
else { | ||
return fail(new TypeError('Descriptor value is not a function.')); | ||
return err(new TypeError('Descriptor value is not a function.')); | ||
} | ||
} | ||
catch (error) { | ||
return fail(error); | ||
return err(error); | ||
} | ||
@@ -110,0 +110,0 @@ }; |
{ | ||
"name": "node-result", | ||
"version": "12.1.0", | ||
"version": "13.0.0", | ||
"description": "result", | ||
@@ -27,10 +27,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/jest": "^27.4.1", | ||
"@types/jest": "^29.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.20.0", | ||
"@typescript-eslint/parser": "^5.20.0", | ||
"eslint": "^8.14.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"husky": "^8.0.3", | ||
"jest": "^29.4.3", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^27.1.4", | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^4.6.3" | ||
@@ -37,0 +37,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7468