@repo/base-service implements an abstract service pattern for domain logic. It provides BaseService<TParams, TResult>—an abstract class where you implement run() and get a perform() method that wraps the result in Safe<TResult> via @repo/safe. It also exports functionify to convert a service class into a simple function call.
flowchart LR
baseService["@repo/base-service"]
safe["@repo/safe"]
ts["@repo/typescript-config"]
vitest["@repo/vitest-config"]
baseService -.-> safe
baseService -.-> ts
baseService -.-> vitestimport { BaseService, functionify } from "@repo/base-service";
class ProcessOrderService extends BaseService<
{ orderId: string },
{ status: string }
> {
protected async run(params: { orderId: string }) {
// Domain logic here
return { status: "processed" };
}
}
// Use as a class
const service = new ProcessOrderService();
const result = await service.perform({ orderId: "123" });
// result: Safe<{ status: string }>
// Or convert to a function
const processOrder = functionify(ProcessOrderService);
const result2 = await processOrder({ orderId: "123" });
| Script | Description |
|---|---|
test |
Run Vitest with coverage |
test:watch |
Run Vitest in watch mode |
check-types |
Typecheck with tsc --noEmit |