bc-webclient-mcp
Version:
Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server
144 lines • 5.58 kB
TypeScript
/**
* Result<T, E> Type for Functional Error Handling
*
* Rust-inspired Result type that forces explicit error handling without exceptions.
* All operations that can fail return Result<T, E> instead of throwing.
*
* @see https://doc.rust-lang.org/std/result/
*/
import type { BCError } from './errors.js';
export type Result<T, E = BCError> = Ok<T> | Err<E>;
export interface Ok<T> {
readonly ok: true;
readonly value: T;
}
export interface Err<E> {
readonly ok: false;
readonly error: E;
}
export declare function ok<T>(value: T): Ok<T>;
export declare function err<E>(error: E): Err<E>;
export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
/**
* Unwraps a Result, returning the value or throwing the error.
* Use only when you're certain the result is Ok.
*
* @throws {E} The error if result is Err
*/
export declare function unwrap<T, E>(result: Result<T, E>): T;
/**
* Unwraps a Result, returning the value or a default value.
* Safe alternative to unwrap().
*/
export declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
/**
* Unwraps a Result, returning the value or computing a default from the error.
*/
export declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
/**
* Returns the error if Result is Err, otherwise throws.
* Use only when you're certain the result is Err.
*
* @throws {Error} If result is Ok
*/
export declare function unwrapErr<T, E>(result: Result<T, E>): E;
/**
* Maps a Result<T, E> to Result<U, E> by applying a function to the Ok value.
*/
export declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
/**
* Maps a Result<T, E> to Result<T, F> by applying a function to the Err value.
*/
export declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
/**
* Applies a function to the Ok value and flattens the result.
* Also known as 'flatMap' or 'bind'.
*/
export declare function andThen<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
/**
* Chains operations, replacing Err with a new Result computed from the error.
*/
export declare function orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
/**
* Combines multiple Results into a single Result containing an array of values.
* If any Result is Err, returns the first error encountered.
*/
export declare function all<T, E>(results: readonly Result<T, E>[]): Result<readonly T[], E>;
/**
* Returns the first Ok result, or the last Err if all are Err.
*/
export declare function any<T, E>(results: readonly Result<T, E>[]): Result<T, E>;
/**
* Combines two Results into a Result containing a tuple.
*/
export declare function combine<T1, T2, E>(r1: Result<T1, E>, r2: Result<T2, E>): Result<readonly [T1, T2], E>;
/**
* Combines three Results into a Result containing a tuple.
*/
export declare function combine3<T1, T2, T3, E>(r1: Result<T1, E>, r2: Result<T2, E>, r3: Result<T3, E>): Result<readonly [T1, T2, T3], E>;
/**
* Maps an async Result with an async function.
*/
export declare function mapAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<U>): Promise<Result<U, E>>;
/**
* Chains async operations.
*/
export declare function andThenAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<Result<U, E>>): Promise<Result<U, E>>;
/**
* Wraps an async operation that might throw into a Result.
*/
export declare function fromPromise<T>(promise: Promise<T>): Promise<Result<T, Error>>;
/**
* Wraps an async operation with a custom error mapper.
*/
export declare function fromPromiseWith<T, E>(promise: Promise<T>, errorMapper: (error: unknown) => E): Promise<Result<T, E>>;
/**
* Wraps a function that might throw into a Result.
*/
export declare function fromThrowable<T>(fn: () => T): Result<T, Error>;
/**
* Wraps a function with a custom error mapper.
*/
export declare function fromThrowableWith<T, E>(fn: () => T, errorMapper: (error: unknown) => E): Result<T, E>;
/**
* Executes a function on the Ok value without transforming the Result.
* Useful for side effects like logging.
*/
export declare function inspect<T, E>(result: Result<T, E>, fn: (value: T) => void): Result<T, E>;
/**
* Executes a function on the Err value without transforming the Result.
* Useful for error logging.
*/
export declare function inspectErr<T, E>(result: Result<T, E>, fn: (error: E) => void): Result<T, E>;
/**
* Matches on a Result, executing one of two functions.
* Forces explicit handling of both Ok and Err cases.
*/
export declare function match<T, E, U>(result: Result<T, E>, handlers: {
ok: (value: T) => U;
err: (error: E) => U;
}): U;
/**
* Async version of match.
*/
export declare function matchAsync<T, E, U>(result: Result<T, E>, handlers: {
ok: (value: T) => Promise<U>;
err: (error: E) => Promise<U>;
}): Promise<U>;
/**
* Partitions an array of Results into two arrays: one with Ok values, one with Err values.
*/
export declare function partition<T, E>(results: readonly Result<T, E>[]): {
ok: readonly T[];
err: readonly E[];
};
/**
* Filters an array of Results, keeping only Ok values.
*/
export declare function filterOk<T, E>(results: readonly Result<T, E>[]): readonly T[];
/**
* Filters an array of Results, keeping only Err values.
*/
export declare function filterErr<T, E>(results: readonly Result<T, E>[]): readonly E[];
//# sourceMappingURL=result.d.ts.map