feat: add file storage service and update configurations
refactor: migrate to tsup for builds and update tsconfigs fix: update error handling and validation in payment service chore: update package scripts and dependencies docs: update README and env examples
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ResultAsync, err, ok } from 'neverthrow';
|
||||
import { AppError } from '../types';
|
||||
import { ResultAsync, err, ok } from "neverthrow";
|
||||
import { AppError } from "../types";
|
||||
|
||||
/**
|
||||
* Wraps a database operation in a Result type to handle errors gracefully
|
||||
@@ -9,7 +9,7 @@ import { AppError } from '../types';
|
||||
*/
|
||||
export const wrapDbOperation = <T, E extends AppError<unknown>>(
|
||||
operation: () => Promise<T>,
|
||||
errorFactory: (error: unknown) => E
|
||||
errorFactory: (error: unknown) => E,
|
||||
): ResultAsync<T, E> => {
|
||||
return ResultAsync.fromPromise(operation(), errorFactory);
|
||||
};
|
||||
@@ -17,9 +17,9 @@ export const wrapDbOperation = <T, E extends AppError<unknown>>(
|
||||
export const wrapDbOperationWithNull = <T, E extends AppError<unknown>>(
|
||||
operation: () => Promise<T | null>,
|
||||
notFoundError: E,
|
||||
dbErrorFactory: (error: unknown) => E
|
||||
dbErrorFactory: (error: unknown) => E,
|
||||
): ResultAsync<T, E> => {
|
||||
return ResultAsync.fromPromise(operation(), (error) =>
|
||||
dbErrorFactory(error)
|
||||
dbErrorFactory(error),
|
||||
).andThen((result) => (result === null ? err(notFoundError) : ok(result)));
|
||||
};
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from './database';
|
||||
export * from './validation';
|
||||
export * from "./database";
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { output, ZodError, ZodObject } from 'zod';
|
||||
|
||||
export const safeParse =
|
||||
<T extends ZodObject>(schema: T) =>
|
||||
<D>(data: D): Result<output<T>, ZodError<output<T>>> => {
|
||||
const parseResult = schema.safeParse(data);
|
||||
|
||||
return parseResult.success ? ok(parseResult.data) : err(parseResult.error);
|
||||
};
|
||||
Reference in New Issue
Block a user