separate types
This commit is contained in:
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import { Result } from '../library/result.js';
|
||||
import { Repository, AppError } from '../infrastructure/repository.js';
|
||||
import { Account, AccountError } from '../domain/account.js';
|
||||
|
||||
export type AccountResult = Result<Account, AccountError>;
|
||||
|
||||
export type WithdrawMoneyFn = (accountId: string, amount: number) => AccountResult;
|
||||
|
||||
export type CreateWithdrawMoneyResult = Result<WithdrawMoneyFn, AppError>;
|
||||
|
||||
export declare const createWithdrawMoney: (repo: Repository) => CreateWithdrawMoneyResult;
|
||||
@@ -3,36 +3,12 @@ import { output, outputError } from '../library/logging.js';
|
||||
import { withdraw } from '../domain/account.js';
|
||||
import { createMoney } from '../domain/money.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../infrastructure/repository.js').Repository} Repository
|
||||
* @typedef {import('../domain/account.js').Account} Account
|
||||
* @typedef {import('../domain/account.js').AccountError} AccountError
|
||||
* @typedef {import('../infrastructure/repository.js').AppError} AppError
|
||||
* @typedef {import('../library/result.js').Result<Account, AccountError>} AccountResult
|
||||
* @typedef {(accountId: string, amount: number) => AccountResult} WithdrawMoneyFn
|
||||
* @typedef {import('../library/result.js').Result<WithdrawMoneyFn, AppError>} CreateWithdrawMoneyResult
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} src
|
||||
* @param {string} msg
|
||||
* @returns {<T, E>(result: import('../library/result.js').Result<T, E>) => import('../library/result.js').Result<T, E>}
|
||||
*/
|
||||
const log = (src, msg) => (result) =>
|
||||
tap((x) => output(src, msg)(x))(tapError((e) => outputError(src, e))(result));
|
||||
|
||||
/**
|
||||
* @param {string} src
|
||||
* @param {(x: T) => string} renderText
|
||||
* @returns {<T, E>(result: import('../library/result.js').Result<T, E>) => import('../library/result.js').Result<T, E>}
|
||||
*/
|
||||
const logWith = (src, renderText) => (result) =>
|
||||
tap((x) => output(src, renderText(x))(x))(tapError((e) => outputError(src, e))(result));
|
||||
|
||||
/**
|
||||
* @param {Repository} repo
|
||||
* @returns {CreateWithdrawMoneyResult}
|
||||
*/
|
||||
export const createWithdrawMoney = (repo) =>
|
||||
ok((accountId, amount) =>
|
||||
pipe(
|
||||
|
||||
Reference in New Issue
Block a user