@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
51 lines (50 loc) • 1.7 kB
TypeScript
/**
* Common interfaces for data processing operations.
*/
import { Either } from "monet";
/** Content returned from a fetch. items and a timestamp. */
export interface Content<T> {
items: Array<T>;
timestamp?: Date;
}
/** Capture error information. */
export interface ErrorInfo {
error?: Error;
message?: string;
timestamp?: Date;
}
/**
* Status may be provided prior to a result being produced.
*/
export interface Status {
inProgress: boolean;
name: string;
message?: string;
timestamp?: Date;
}
/** Makes a status and automatically sets the timestamp to now. */
export declare function mkStatus(inProgress: boolean, name: string, message?: string): {
inProgress: boolean;
name: string;
message: string | undefined;
timestamp: Date;
};
/** Result of fetch. Left is error. */
export declare type Result<T = any, E = ErrorInfo> = Either<E, Content<T>>;
/**
* Smart constructors for Result<T, ErrorInfo> instances. If you don't
* use `E=ErrorInfo` you will need to create your own if you want.
*/
export declare const ResultOps: {
ok: <T = any>(c: Content<T>) => Either<ErrorInfo, Content<T>>;
error: <T = any>(e: ErrorInfo) => Either<ErrorInfo, Content<T>>;
errorNow: <T = any>(error: Error, message?: string | undefined) => Either<ErrorInfo, Content<T>>;
okNow: <T = any>(items?: T[]) => Either<ErrorInfo, Content<T>>;
};
/**
* A type often used when retrieving results that then get
* indexed by name. You'll probably wrap non-null results
* in a Maybe so you have `Maybe<NamedArrayTuple>` which
* you then filter and map (e.g. `collect` or `reduce`).
*/
export declare type NamedArrayTuple<T> = [string, Array<T>];