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:
Yuu Ottosoka
2025-07-12 16:01:57 +03:00
parent c0c04bbdba
commit f9ecac94f2
67 changed files with 3308 additions and 695 deletions

View File

@@ -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)));
};

View File

@@ -1,2 +1 @@
export * from './database';
export * from './validation';
export * from "./database";

View File

@@ -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);
};