UNPKG

@overture-stack/lyric

Version:
46 lines (45 loc) 1.46 kB
export type Success<SuccessData> = { success: true; data: SuccessData; }; type DefaultFailureData = string; export type Failure<FailureData = DefaultFailureData> = { success: false; data: FailureData; }; /** * Represents a response that on success will include data of type T, * otherwise a message will be returned in place of the data explaining the failure. * * Optionally, a data type can be provided for the failure case. */ export type Result<SuccessData, FailureData = DefaultFailureData> = Success<SuccessData> | Failure<FailureData>; /** * Async Reporesentation of Result type, where the result is wrapped in a Promise. */ export type AsyncResult<SuccessData, FailureData = DefaultFailureData> = Promise<Result<SuccessData, FailureData>>; /** * Create a successful response for a Result or Either type, with data of the success type * @param {T} data * @returns {Success<T>} `{success: true, data}` */ export declare const success: <T>(data: T) => Success<T>; /** * Create a failure response with data. * @param {T} data * @returns {Failure<T>} `{success: false, data}` */ export declare const failure: <T>(data: T) => Failure<T>; /** * Represents a paginated result array of type T * and metadata with the total number of records * and an optional error message */ export type PaginatedResult<T> = { metadata: { totalRecords: number; errorMessage?: string; }; result: T[]; }; export {};