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-core

Included Exports

ExportDescription
ServiceBaseGeneric CRUD base class (create, getAll, getById, update, remove)
ServiceBaseTenantTenant-scoped CRUD service. All operations run inside an RLS transaction.
UtilTenantScopetenantScope and systemScope transaction wrappers for configuring RLS context.
UtilDbSchemaSchema helpers: tenantIsolationPolicy, activeIndex.
UtilAuditscrub() — removes sensitive fields from audit logs.
MacroRoleGuardElysia macro for role-based access control.
MacroPlanGuardElysia 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();