@konkon5991/pipeline-ts
Version:
A lightweight TypeScript library for Railway Oriented Programming (ROP) with comprehensive functional programming utilities.
100 lines • 4.33 kB
TypeScript
import { Result } from './result';
/**
* Debug configuration options.
*/
export interface DebugOptions {
label?: string;
includeTimestamp?: boolean;
includeStack?: boolean;
logger?: (message: string) => void;
}
/**
* Inspects a result value with optional debugging information.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {DebugOptions} options - Debug options.
* @returns {(result: Result<T, E>) => Result<T, E>} - A function that inspects and returns the result.
*/
export declare const inspect: <T, E>(options?: DebugOptions) => (result: Result<T, E>) => Result<T, E>;
/**
* Traces the execution time of a function.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {string} label - Label for the trace.
* @param {(result: Result<T, E>) => Result<T, E> | Promise<Result<T, E>>} fn - Function to trace.
* @returns {(result: Result<T, E>) => Promise<Result<T, E>>} - A function that traces execution time.
*/
export declare const trace: <T, E>(label: string, fn: (result: Result<T, E>) => Result<T, E> | Promise<Result<T, E>>) => (result: Result<T, E>) => Promise<Result<T, E>>;
/**
* Logs a custom message based on the result.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {Object} messages - Custom messages for success and failure.
* @param {(value: T) => string} messages.onSuccess - Message generator for success.
* @param {(error: E) => string} messages.onFailure - Message generator for failure.
* @param {(message: string) => void} logger - Logger function.
* @returns {(result: Result<T, E>) => Result<T, E>} - A function that logs and returns the result.
*/
export declare const log: <T, E>(messages: {
onSuccess?: (value: T) => string;
onFailure?: (error: E) => string;
}, logger?: (message: string) => void) => (result: Result<T, E>) => Result<T, E>;
/**
* Creates a breakpoint for debugging.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {(result: Result<T, E>) => boolean} condition - Condition to trigger breakpoint.
* @returns {(result: Result<T, E>) => Result<T, E>} - A function that conditionally triggers debugger.
*/
export declare const breakpoint: <T, E>(condition?: (result: Result<T, E>) => boolean) => (result: Result<T, E>) => Result<T, E>;
/**
* Asserts a condition on a successful result.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {(value: T) => boolean} predicate - Assertion predicate.
* @param {string} message - Error message if assertion fails.
* @returns {(result: Result<T, E>) => Result<T, E | Error>} - A function that asserts and returns the result.
*/
export declare const assert: <T, E>(predicate: (value: T) => boolean, message: string) => (result: Result<T, E>) => Result<T, E | Error>;
/**
* Creates a pipeline debugger that tracks all transformations.
*/
export declare class PipelineDebugger {
private steps;
/**
* Wraps a function to track its execution.
* @template T - The type of the value in case of success.
* @template E - The type of the error in case of failure.
* @param {string} label - Label for this step.
* @param {Function} fn - Function to wrap.
* @returns {Function} - Wrapped function that tracks execution.
*/
wrap<T, E>(label: string, fn: (input: any) => Result<T, E> | Promise<Result<T, E>>): (input: any) => Promise<Result<T, E>>;
/**
* Gets the debug report.
* @returns {Object} - Debug report with all steps and total duration.
*/
getReport(): {
steps: {
label: string;
duration: number;
result: any;
}[];
totalDuration: number;
averageDuration: number;
slowestStep: {
label: string;
duration: number;
result: any;
} | null;
};
/**
* Prints the debug report.
*/
printReport(): void;
/**
* Clears the debug history.
*/
clear(): void;
}
//# sourceMappingURL=debug.d.ts.map