UNPKG

@synet/identity

Version:

Simple and secure identity management library for Verifiable Identity

85 lines (84 loc) 2.64 kB
/** * Minimal Result pattern for @synet/credential * * API-compatible with @synet/patterns Result but self-contained. * Removes unused methods (map, flatMap, recover, ensure, combine). */ /** * A simple and versatile Result pattern implementation * Used for representing the outcome of operations that might fail */ export declare class Result<T> { private readonly _isSuccess; private readonly _value?; private readonly _error?; private constructor(); /** * Returns whether this Result represents a successful operation */ get isSuccess(): boolean; /** * Returns whether this Result represents a failed operation */ get isFailure(): boolean; /** * Returns the success value * @throws Error if called on a failed result */ get value(): T; /** * Returns the error details if this is a failure result */ get error(): { message: string; cause?: Error; data?: unknown[]; } | undefined; /** * Returns the error message if this is a failure result */ get errorMessage(): string | undefined; /** * Returns the error cause if this is a failure result */ get errorCause(): Error | undefined; /** * Creates a successful result with a value * @param value The success value */ static success<T>(value: T): Result<T>; /** * Creates a failure result with a message, optional cause, and optional context data * @param message Error message describing what went wrong * @param cause Optional underlying error that caused the failure * @param data Optional additional context data for debugging */ static fail<T>(message: string, cause?: Error, ...data: unknown[]): Result<T>; /** * Executes the given callback if this is a success result * @param fn Function to execute with the success value * @returns This result, for method chaining */ onSuccess(fn: (value: T) => void): Result<T>; /** * Executes the given callback if this is a failure result * @param fn Function to execute with the error details * @returns This result, for method chaining */ onFailure(fn: (message: string, cause?: Error, data?: unknown[]) => void): Result<T>; /** * Checks if the result is null * @returns true if the result is null, false otherwise */ isNull(): boolean; } /** * Credential-specific result types */ export interface VerificationResult { verified: boolean; issuer?: string; subject?: string; issuanceDate?: string; expirationDate?: string; }