Bedest Core
Core abstractions for the Bedest BED stack (Bun + Elysia + Drizzle).
The shared foundation of the Bedest ecosystem is extracted into bedest-core, a zero-dependency (peer-only) npm package. It keeps your projects clean by hiding repetitive boilerplate logic for CRUD operations, pagination, access guards, and schemas.
Installation
bun add bedest-coreIncluded Exports
| Export | Description |
|---|---|
ServiceBase | Generic CRUD base class (create, getAll, getById, update, remove) |
ServiceBaseTenant | Tenant-scoped CRUD service. All operations run inside an RLS transaction. |
UtilTenantScope | tenantScope and systemScope transaction wrappers for configuring RLS context. |
UtilDbSchema | Schema helpers: tenantIsolationPolicy, activeIndex. |
UtilAudit | scrub() — removes sensitive fields from audit logs. |
MacroRoleGuard | Elysia macro for role-based access control. |
MacroPlanGuard | Elysia macro for tenant plan-based access control. |
Examples
1. MacroRoleGuard
Register the macro in your application context, then use it directly in Elysia routes:
import { MacroRoleGuard } from "bedest-core";
// Register
.macro("RoleGuard", MacroRoleGuard)
// Use
{
RoleGuard: ["ADMIN", "SYSTEM"]
}
2. ServiceBaseTenant
Eliminate boilerplate by inheriting from the core tenant service:
import { ServiceBaseTenant } from "bedest-core";
import { SMyTable } from "../schemas/SMyTable";
class ServiceMyEntity extends ServiceBaseTenant<typeof SMyTable> {
constructor() {
super(SMyTable);
}
}
export default new ServiceMyEntity();
